diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/blocks.c | 12 | ||||
-rw-r--r-- | src/cmark.h | 1 | ||||
-rw-r--r-- | src/inlines.c | 12 |
3 files changed, 16 insertions, 9 deletions
diff --git a/src/blocks.c b/src/blocks.c index ae106d2..7613c82 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -432,15 +432,15 @@ static void chop_trailing_hashtags(chunk *ch) chunk_rtrim(ch); orig_n = n = ch->len - 1; - // if string ends in #s, remove these: + // if string ends in space followed by #s, remove these: while (n >= 0 && peek_at(ch, n) == '#') n--; - // the last # was escaped, so we include it. - if (n != orig_n && n >= 0 && peek_at(ch, n) == '\\') - n++; - - ch->len = n + 1; + // Check for a be a space before the final #s: + if (n != orig_n && n >= 0 && peek_at(ch, n) == ' ') { + ch->len = n; + chunk_rtrim(ch); + } } // Process one line at a time, modifying a node_block. diff --git a/src/cmark.h b/src/cmark.h index ff2f9a2..e34df72 100644 --- a/src/cmark.h +++ b/src/cmark.h @@ -9,6 +9,7 @@ #define VERSION "0.1" #define CODE_INDENT 4 +#define STACK_LIMIT 1000 struct node_inl { enum { diff --git a/src/inlines.c b/src/inlines.c index 7a7f08a..9216979 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -23,6 +23,7 @@ typedef struct Subject { int label_nestlevel; reference_map *refmap; inline_stack *emphasis_openers; + int emphasis_nestlevel; } subject; static node_inl *parse_chunk_inlines(chunk *chunk, reference_map *refmap); @@ -177,6 +178,7 @@ static void subject_from_buf(subject *e, strbuf *buffer, reference_map *refmap) e->label_nestlevel = 0; e->refmap = refmap; e->emphasis_openers = NULL; + e->emphasis_nestlevel = 0; chunk_rtrim(&e->input); } @@ -190,6 +192,7 @@ static void subject_from_chunk(subject *e, chunk *chunk, reference_map *refmap) e->label_nestlevel = 0; e->refmap = refmap; e->emphasis_openers = NULL; + e->emphasis_nestlevel = 0; chunk_rtrim(&e->input); } @@ -309,6 +312,7 @@ static void free_openers(subject* subj, inline_stack* istack) while (subj->emphasis_openers != istack) { tempstack = subj->emphasis_openers; subj->emphasis_openers = subj->emphasis_openers->previous; + subj->emphasis_nestlevel--; free(tempstack); } } @@ -389,7 +393,7 @@ static node_inl* handle_strong_emph(subject* subj, unsigned char c, node_inl **l cannotClose: inl_text = make_str(chunk_dup(&subj->input, subj->pos - numdelims, numdelims)); - if (can_open) + if (can_open && subj->emphasis_nestlevel < STACK_LIMIT) { istack = (inline_stack*)malloc(sizeof(inline_stack)); if (istack == NULL) { @@ -400,6 +404,7 @@ cannotClose: istack->first_inline = inl_text; istack->previous = subj->emphasis_openers; subj->emphasis_openers = istack; + subj->emphasis_nestlevel++; } return inl_text; @@ -589,7 +594,8 @@ static int link_label(subject* subj, chunk *raw_label) advance(subj); // advance past [ unsigned char c; - while ((c = peek_char(subj)) && (c != ']' || nestlevel > 0)) { + while ((c = peek_char(subj)) && + (c != ']' || (nestlevel > 0 && nestlevel < STACK_LIMIT))) { switch (c) { case '`': tmp = handle_backticks(subj); @@ -617,7 +623,7 @@ static int link_label(subject* subj, chunk *raw_label) advance(subj); } } - if (c == ']') { + if (nestlevel == 0 && c == ']') { *raw_label = chunk_dup(&subj->input, startpos + 1, subj->pos - (startpos + 1)); subj->label_nestlevel = 0; advance(subj); // advance past ] |