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->bold = false;
ret->underlined = false;
ret->strikeout = false;
return ret;
}
@ -375,7 +376,7 @@ static pmh_style_attribute *interpret_attributes(style_parser_data *p_data,
raw_attribute *raw_attributes)
{
pmh_style_attribute *attrs = NULL;
raw_attribute *cur = raw_attributes;
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);
attr->lang_element_type = lang_element_type;
attr->value = new_attr_value();
if (atype == pmh_attr_type_foreground_color
|| atype == pmh_attr_type_background_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();
attr->value->font_size = fs;
char *trimmed_value = trim_str_dup(cur->value);
fs->is_relative = (*trimmed_value == '+' || *trimmed_value == '-');
char *endptr = NULL;
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);
attr = NULL;
}
free(trimmed_value);
}
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)
{
char *standardized_value = standardize_str(value_cur->value);
if (EQUALS(standardized_value, "italic"))
attr->value->font_styles->italic = true;
else if (EQUALS(standardized_value, "bold"))
attr->value->font_styles->bold = true;
else if (EQUALS(standardized_value, "underlined"))
attr->value->font_styles->underlined = true;
else if (EQUALS(standardized_value, "strikeout"))
attr->value->font_styles->strikeout = true;
else {
report_error(p_data, cur->line_number,
"Value '%s' is invalid for attribute '%s'",
standardized_value, cur->name);
}
free(standardized_value);
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);
}
if (attr != NULL) {
// add to linked list
attr->next = attrs;
attrs = attr;
}
cur = cur->next;
}
return attrs;
}

View File

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

View File

@ -811,7 +811,7 @@ void HGMarkdownHighlighter::parseInternal()
memcpy(content, data, len);
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)

View File

@ -130,7 +130,7 @@ foreground: 5c6370
VERBATIM
foreground: 98c379
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
# Could specify multiple attribute in one line
hljs-comment: 5c6370
@ -172,4 +172,5 @@ BLOCKQUOTE
foreground: 5c6370
STRIKE
strike-color: 586e75
foreground: e57373
font-style: strikeout

View File

@ -129,7 +129,7 @@ foreground: 93a1a1
VERBATIM
foreground: 673ab7
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
hljs-comment: 6c6c6c
hljs-keyword: 0000ee
@ -170,4 +170,5 @@ BLOCKQUOTE
foreground: 00af00
STRIKE
strike-color: 586e75
foreground: b71c1c
font-style: strikeout

View File

@ -130,7 +130,7 @@ foreground: 93a1a1
VERBATIM
foreground: 673ab7
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
# Could specify multiple attribute in one line
hljs-comment: 6c6c6c
@ -171,4 +171,5 @@ BLOCKQUOTE
foreground: 00af00
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) {
format.setFontItalic(true);
}
if (fontStyle->bold) {
format.setFontWeight(QFont::Bold);
}
if (fontStyle->underlined) {
format.setFontUnderline(true);
}
if (fontStyle->strikeout) {
format.setFontStrikeOut(true);
}
break;
}
@ -159,6 +166,8 @@ QHash<QString, QTextCharFormat> VStyleParser::fetchCodeBlockStyles(const QFont &
format.setFontItalic(true);
} else if (val == "underlined") {
format.setFontUnderline(true);
} else if (val == "strikeout") {
format.setFontStrikeOut(true);
} else {
// Treat it as the color RGB value string without '#'.
QColor color("#" + val);