Support strikethrough

This commit is contained in:
jpirnay
2026-04-29 09:08:07 +02:00
parent 93f5bdb492
commit b83482e732
11 changed files with 242 additions and 44 deletions
+26 -6
View File
@@ -4,11 +4,22 @@
namespace MdParser {
static EpdFontFamily::Style combineFlags(bool bold, bool italic) {
if (bold && italic) return EpdFontFamily::BOLD_ITALIC;
if (bold) return EpdFontFamily::BOLD;
if (italic) return EpdFontFamily::ITALIC;
return EpdFontFamily::REGULAR;
static EpdFontFamily::Style combineFlags(bool bold, bool italic, bool strike) {
EpdFontFamily::Style result = EpdFontFamily::REGULAR;
if (bold)
result =
static_cast<EpdFontFamily::Style>(static_cast<uint8_t>(result) | static_cast<uint8_t>(EpdFontFamily::BOLD));
if (italic)
result =
static_cast<EpdFontFamily::Style>(static_cast<uint8_t>(result) | static_cast<uint8_t>(EpdFontFamily::ITALIC));
if (bold && italic)
result = static_cast<EpdFontFamily::Style>(
static_cast<uint8_t>(EpdFontFamily::BOLD_ITALIC) |
(static_cast<uint8_t>(result) & static_cast<uint8_t>(EpdFontFamily::STRIKETHROUGH)));
if (strike)
result = static_cast<EpdFontFamily::Style>(static_cast<uint8_t>(result) |
static_cast<uint8_t>(EpdFontFamily::STRIKETHROUGH));
return result;
}
static constexpr int TAB_WIDTH = 4;
@@ -63,11 +74,12 @@ std::vector<Span> parseInline(const std::string& text) {
std::string current;
bool bold = false;
bool italic = false;
bool strike = false;
size_t i = 0;
auto emitSpan = [&]() {
if (!current.empty()) {
spans.push_back({std::move(current), combineFlags(bold, italic)});
spans.push_back({std::move(current), combineFlags(bold, italic, strike)});
current.clear();
}
};
@@ -111,6 +123,14 @@ std::vector<Span> parseInline(const std::string& text) {
continue;
}
// ~~ — toggle strikethrough
if (c == '~' && i + 1 < text.size() && text[i + 1] == '~') {
emitSpan();
strike = !strike;
i += 2;
continue;
}
// ** or __ — toggle bold
if ((c == '*' || c == '_') && i + 1 < text.size() && text[i + 1] == c) {
if (c == '_' && !isUnderscoreEmphasis(text, i, 2)) {