style: support STRIKE and NOTES

- Add "strikeout" support in mdhl file;
This commit is contained in:
Le Tan 2018-05-05 13:41:53 +08:00
parent 6558fa85b7
commit e2dd062a24
7 changed files with 33 additions and 17 deletions

View File

@ -212,6 +212,7 @@ static pmh_attr_font_styles *new_font_styles()
ret->italic = false; ret->italic = false;
ret->bold = false; ret->bold = false;
ret->underlined = false; ret->underlined = false;
ret->strikeout = false;
return ret; return ret;
} }
@ -437,6 +438,8 @@ static pmh_style_attribute *interpret_attributes(style_parser_data *p_data,
attr->value->font_styles->bold = true; attr->value->font_styles->bold = true;
else if (EQUALS(standardized_value, "underlined")) else if (EQUALS(standardized_value, "underlined"))
attr->value->font_styles->underlined = true; attr->value->font_styles->underlined = true;
else if (EQUALS(standardized_value, "strikeout"))
attr->value->font_styles->strikeout = true;
else { else {
report_error(p_data, cur->line_number, report_error(p_data, cur->line_number,
"Value '%s' is invalid for attribute '%s'", "Value '%s' is invalid for attribute '%s'",

View File

@ -33,6 +33,7 @@ typedef struct
bool italic; bool italic;
bool bold; bool bold;
bool underlined; bool underlined;
bool strikeout;
} pmh_attr_font_styles; } pmh_attr_font_styles;
/** \brief Font size attribute value. */ /** \brief Font size attribute value. */

View File

@ -811,7 +811,7 @@ void HGMarkdownHighlighter::parseInternal()
memcpy(content, data, len); memcpy(content, data, len);
content[len] = '\0'; content[len] = '\0';
pmh_markdown_to_elements(content, pmh_EXT_NONE, &result); pmh_markdown_to_elements(content, pmh_EXT_STRIKE, &result);
} }
void HGMarkdownHighlighter::handleContentChange(int /* position */, int charsRemoved, int charsAdded) void HGMarkdownHighlighter::handleContentChange(int /* position */, int charsRemoved, int charsAdded)

View File

@ -130,7 +130,7 @@ foreground: 5c6370
VERBATIM VERBATIM
foreground: 98c379 foreground: 98c379
font-family: Consolas, Monaco, Andale Mono, Monospace, Courier New font-family: Consolas, Monaco, Andale Mono, Monospace, Courier New
# [VNote] Codeblock sylte from HighlightJS (bold, italic, underlined, color) # [VNote] Codeblock sylte from HighlightJS (bold, italic, underlined, strikeout, color)
# The last occurence of the same attribute takes effect # The last occurence of the same attribute takes effect
# Could specify multiple attribute in one line # Could specify multiple attribute in one line
hljs-comment: 5c6370 hljs-comment: 5c6370
@ -172,4 +172,5 @@ BLOCKQUOTE
foreground: 5c6370 foreground: 5c6370
STRIKE STRIKE
strike-color: 586e75 foreground: e57373
font-style: strikeout

View File

@ -129,7 +129,7 @@ foreground: 93a1a1
VERBATIM VERBATIM
foreground: 673ab7 foreground: 673ab7
font-family: Consolas, Monaco, Andale Mono, Monospace, Courier New font-family: Consolas, Monaco, Andale Mono, Monospace, Courier New
# [VNote] Codeblock sylte from HighlightJS (bold, italic, underlined, color) # [VNote] Codeblock sylte from HighlightJS (bold, italic, underlined, strikeout, color)
# The last occurence of the same attribute takes effect # The last occurence of the same attribute takes effect
hljs-comment: 6c6c6c hljs-comment: 6c6c6c
hljs-keyword: 0000ee hljs-keyword: 0000ee
@ -170,4 +170,5 @@ BLOCKQUOTE
foreground: 00af00 foreground: 00af00
STRIKE STRIKE
strike-color: 586e75 foreground: b71c1c
font-style: strikeout

View File

@ -130,7 +130,7 @@ foreground: 93a1a1
VERBATIM VERBATIM
foreground: 673ab7 foreground: 673ab7
font-family: Consolas, Monaco, Andale Mono, Monospace, Courier New font-family: Consolas, Monaco, Andale Mono, Monospace, Courier New
# [VNote] Codeblock sylte from HighlightJS (bold, italic, underlined, color) # [VNote] Codeblock sylte from HighlightJS (bold, italic, underlined, strikeout, color)
# The last occurence of the same attribute takes effect # The last occurence of the same attribute takes effect
# Could specify multiple attribute in one line # Could specify multiple attribute in one line
hljs-comment: 6c6c6c hljs-comment: 6c6c6c
@ -171,4 +171,5 @@ BLOCKQUOTE
foreground: 00af00 foreground: 00af00
STRIKE STRIKE
strike-color: 586e75 foreground: b71c1c
font-style: strikeout

View File

@ -88,12 +88,19 @@ QTextCharFormat VStyleParser::QTextCharFormatFromAttrs(pmh_style_attribute *attr
if (fontStyle->italic) { if (fontStyle->italic) {
format.setFontItalic(true); format.setFontItalic(true);
} }
if (fontStyle->bold) { if (fontStyle->bold) {
format.setFontWeight(QFont::Bold); format.setFontWeight(QFont::Bold);
} }
if (fontStyle->underlined) { if (fontStyle->underlined) {
format.setFontUnderline(true); format.setFontUnderline(true);
} }
if (fontStyle->strikeout) {
format.setFontStrikeOut(true);
}
break; break;
} }
@ -159,6 +166,8 @@ QHash<QString, QTextCharFormat> VStyleParser::fetchCodeBlockStyles(const QFont &
format.setFontItalic(true); format.setFontItalic(true);
} else if (val == "underlined") { } else if (val == "underlined") {
format.setFontUnderline(true); format.setFontUnderline(true);
} else if (val == "strikeout") {
format.setFontStrikeOut(true);
} else { } else {
// Treat it as the color RGB value string without '#'. // Treat it as the color RGB value string without '#'.
QColor color("#" + val); QColor color("#" + val);