From 99c3881dd078da45dc540ff271e73a9831d5d432 Mon Sep 17 00:00:00 2001 From: baylej Date: Wed, 11 Oct 2017 01:06:57 +0200 Subject: 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 --- src/blogc/content-parser.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src') 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: -- cgit v1.2.3-18-g5258