aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbaylej <baylej@mrhide.eu>2017-10-11 01:06:57 +0200
committerRafael Martins <rafael@rafaelmartins.eng.br>2017-10-25 04:32:02 +0200
commit99c3881dd078da45dc540ff271e73a9831d5d432 (patch)
tree46478c3f847feb9c30e3b681f2e8a0915f74c3cd
parentd97b40aa34f53b612900e992c66d321878d7f976 (diff)
downloadblogc-99c3881dd078da45dc540ff271e73a9831d5d432.tar.gz
blogc-99c3881dd078da45dc540ff271e73a9831d5d432.tar.bz2
blogc-99c3881dd078da45dc540ff271e73a9831d5d432.zip
Allow lines starting with * or **
These are emphasizing markups per the "Markdown standard". A line containing two '*' or '+' or '-' are not valid horizontal rules. See: https://daringfireball.net/projects/markdown/syntax#hr
-rw-r--r--src/blogc/content-parser.c31
-rw-r--r--tests/blogc/check_content_parser.c12
2 files changed, 30 insertions, 13 deletions
diff --git a/src/blogc/content-parser.c b/src/blogc/content-parser.c
index 9aa26dc..e971296 100644
--- a/src/blogc/content-parser.c
+++ b/src/blogc/content-parser.c
@@ -138,7 +138,8 @@ typedef enum {
CONTENT_CODE,
CONTENT_CODE_START,
CONTENT_CODE_END,
- CONTENT_UNORDERED_LIST_OR_HORIZONTAL_RULE,
+ CONTENT_UNORDERED_LIST_OR_HORIZONTAL_RULE_OR_EMPHASIS,
+ CONTENT_HORIZONTAL_RULE_OR_EMPHASIS,
CONTENT_HORIZONTAL_RULE,
CONTENT_UNORDERED_LIST_START,
CONTENT_UNORDERED_LIST_END,
@@ -758,7 +759,7 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
}
if (c == '*' || c == '+' || c == '-') {
start2 = current;
- state = CONTENT_UNORDERED_LIST_OR_HORIZONTAL_RULE;
+ state = CONTENT_UNORDERED_LIST_OR_HORIZONTAL_RULE_OR_EMPHASIS;
d = c;
break;
}
@@ -1001,17 +1002,33 @@ blogc_content_parse(const char *src, size_t *end_excerpt, char **first_header,
}
break;
- case CONTENT_UNORDERED_LIST_OR_HORIZONTAL_RULE:
+ case CONTENT_UNORDERED_LIST_OR_HORIZONTAL_RULE_OR_EMPHASIS:
+ if (current == start+1) {
+ if (c == d) { // horizontal rule or '**' emphasis
+ state = CONTENT_HORIZONTAL_RULE_OR_EMPHASIS;
+ break;
+ }
+ else if (c != ' ' && c != '\t' && d == '*') { // is '*' emphasis
+ state = CONTENT_PARAGRAPH;
+ break;
+ }
+ }
+ if (c == ' ' || c == '\t')
+ break;
+ prefix = bc_strndup(src + start, current - start);
+ state = CONTENT_UNORDERED_LIST_START;
+ break;
+
+ case CONTENT_HORIZONTAL_RULE_OR_EMPHASIS:
+ // 3rd '-' or '*' required for a horizontal rule
if (c == d) {
state = CONTENT_HORIZONTAL_RULE;
if (is_last)
continue;
break;
}
- if (c == ' ' || c == '\t')
- break;
- prefix = bc_strndup(src + start, current - start);
- state = CONTENT_UNORDERED_LIST_START;
+ // is '**' emphasis
+ state = CONTENT_PARAGRAPH;
break;
case CONTENT_HORIZONTAL_RULE:
diff --git a/tests/blogc/check_content_parser.c b/tests/blogc/check_content_parser.c
index a94e5ad..5c85fc0 100644
--- a/tests/blogc/check_content_parser.c
+++ b/tests/blogc/check_content_parser.c
@@ -696,7 +696,7 @@ test_content_parse_code_crlf(void **state)
static void
test_content_parse_horizontal_rule(void **state)
{
- char *html = blogc_content_parse("bola\nguda\n\n**", NULL, NULL, NULL);
+ char *html = blogc_content_parse("bola\nguda\n\n***", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\n"
@@ -710,7 +710,7 @@ test_content_parse_horizontal_rule(void **state)
"guda</p>\n"
"<hr />\n");
free(html);
- html = blogc_content_parse("bola\nguda\n\n--\n", NULL, NULL, NULL);
+ html = blogc_content_parse("bola\nguda\n\n---\n", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\n"
@@ -727,7 +727,7 @@ test_content_parse_horizontal_rule(void **state)
html = blogc_content_parse(
"bola\n"
"\n"
- "**\n"
+ "***\n"
"\n"
"chunda\n", NULL, NULL, NULL);
assert_non_null(html);
@@ -754,7 +754,7 @@ test_content_parse_horizontal_rule(void **state)
static void
test_content_parse_horizontal_rule_crlf(void **state)
{
- char *html = blogc_content_parse("bola\r\nguda\r\n\r\n**", NULL, NULL, NULL);
+ char *html = blogc_content_parse("bola\r\nguda\r\n\r\n***", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\r\n"
@@ -768,7 +768,7 @@ test_content_parse_horizontal_rule_crlf(void **state)
"guda</p>\r\n"
"<hr />\r\n");
free(html);
- html = blogc_content_parse("bola\r\nguda\r\n\r\n--\r\n", NULL, NULL, NULL);
+ html = blogc_content_parse("bola\r\nguda\r\n\r\n---\r\n", NULL, NULL, NULL);
assert_non_null(html);
assert_string_equal(html,
"<p>bola\r\n"
@@ -785,7 +785,7 @@ test_content_parse_horizontal_rule_crlf(void **state)
html = blogc_content_parse(
"bola\r\n"
"\r\n"
- "**\r\n"
+ "***\r\n"
"\r\n"
"chunda\r\n", NULL, NULL, NULL);
assert_non_null(html);