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;
} }
@ -375,7 +376,7 @@ static pmh_style_attribute *interpret_attributes(style_parser_data *p_data,
raw_attribute *raw_attributes) raw_attribute *raw_attributes)
{ {
pmh_style_attribute *attrs = NULL; pmh_style_attribute *attrs = NULL;
raw_attribute *cur = raw_attributes; raw_attribute *cur = raw_attributes;
while (cur != NULL) while (cur != NULL)
{ {
@ -383,7 +384,7 @@ static pmh_style_attribute *interpret_attributes(style_parser_data *p_data,
pmh_style_attribute *attr = new_attr(cur->name, atype); pmh_style_attribute *attr = new_attr(cur->name, atype);
attr->lang_element_type = lang_element_type; attr->lang_element_type = lang_element_type;
attr->value = new_attr_value(); attr->value = new_attr_value();
if (atype == pmh_attr_type_foreground_color if (atype == pmh_attr_type_foreground_color
|| atype == pmh_attr_type_background_color || atype == pmh_attr_type_background_color
|| atype == pmh_attr_type_caret_color || atype == pmh_attr_type_caret_color
@ -402,9 +403,9 @@ static pmh_style_attribute *interpret_attributes(style_parser_data *p_data,
{ {
pmh_attr_font_size *fs = new_font_size(); pmh_attr_font_size *fs = new_font_size();
attr->value->font_size = fs; attr->value->font_size = fs;
char *trimmed_value = trim_str_dup(cur->value); char *trimmed_value = trim_str_dup(cur->value);
fs->is_relative = (*trimmed_value == '+' || *trimmed_value == '-'); fs->is_relative = (*trimmed_value == '+' || *trimmed_value == '-');
char *endptr = NULL; char *endptr = NULL;
fs->size_pt = (int)strtol(cur->value, &endptr, 10); fs->size_pt = (int)strtol(cur->value, &endptr, 10);
@ -415,7 +416,7 @@ static pmh_style_attribute *interpret_attributes(style_parser_data *p_data,
free_style_attributes(attr); free_style_attributes(attr);
attr = NULL; attr = NULL;
} }
free(trimmed_value); free(trimmed_value);
} }
else if (atype == pmh_attr_type_font_family) else if (atype == pmh_attr_type_font_family)
@ -430,19 +431,21 @@ static pmh_style_attribute *interpret_attributes(style_parser_data *p_data,
while (value_cur != NULL) while (value_cur != NULL)
{ {
char *standardized_value = standardize_str(value_cur->value); char *standardized_value = standardize_str(value_cur->value);
if (EQUALS(standardized_value, "italic")) if (EQUALS(standardized_value, "italic"))
attr->value->font_styles->italic = true; attr->value->font_styles->italic = true;
else if (EQUALS(standardized_value, "bold")) else if (EQUALS(standardized_value, "bold"))
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'",
standardized_value, cur->name); standardized_value, cur->name);
} }
free(standardized_value); free(standardized_value);
value_cur = value_cur->next; value_cur = value_cur->next;
} }
@ -452,16 +455,16 @@ static pmh_style_attribute *interpret_attributes(style_parser_data *p_data,
{ {
attr->value->string = trim_str_dup(cur->value); attr->value->string = trim_str_dup(cur->value);
} }
if (attr != NULL) { if (attr != NULL) {
// add to linked list // add to linked list
attr->next = attrs; attr->next = attrs;
attrs = attr; attrs = attr;
} }
cur = cur->next; cur = cur->next;
} }
return attrs; return attrs;
} }

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);