md4c

C Markdown parser. Fast. SAX-like interface. Compliant to CommonMark specification.
git clone https://noulin.net/git/md4c.git
Log | Files | Refs | README | LICENSE

commit f1bd8b37c04428861ae88482e7cd82aa02e54978
parent 2a70b3efa199ccb5616d41c611d5c7cadf926b6a
Author: Martin Mitas <mity@morous.org>
Date:   Sat, 26 Nov 2016 21:57:24 +0100

Fix handling of multi-backtick codespan mark if a backslash precedes.

So in this

    \``code span`

the codespan is now correctly recognized.

Diffstat:
Mmd4c/md4c.c | 26++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/md4c/md4c.c b/md4c/md4c.c @@ -2294,17 +2294,8 @@ md_collect_marks(MD_CTX* ctx, const MD_LINE* lines, int n_lines) /* We limit code span marks to lower then 256 backticks. This * solves a pathologic case of too many openers, each of * different length: Their resolving is then O(n^2). */ - if(tmp - off < 256) { - unsigned flags; - - /* It may be opener only if it is not escaped. */ - if(ctx->n_marks > 0 && ctx->marks[ctx->n_marks-1].beg == off-1 && CH(off-1) == _T('\\')) - flags = MD_MARK_POTENTIAL_CLOSER; - else - flags = MD_MARK_POTENTIAL_OPENER | MD_MARK_POTENTIAL_CLOSER; - - PUSH_MARK(ch, off, tmp, flags); - } + if(tmp - off < 256) + PUSH_MARK(ch, off, tmp, MD_MARK_POTENTIAL_OPENER | MD_MARK_POTENTIAL_CLOSER); off = tmp; continue; @@ -2476,7 +2467,18 @@ md_analyze_backtick(MD_CTX* ctx, int mark_index) } /* We didn't find any matching opener, so we ourselves may be the opener - * of some upcoming closer. */ + * of some upcoming closer. We also have to handle specially if there is + * a backslash mark before it as that can cancel the first backtick. */ + if(mark_index > 0 && (mark-1)->beg == mark->beg - 1 && (mark-1)->ch == '\\') { + if(mark->end - mark->beg == 1) { + /* Single escaped backtick. */ + return; + } + + /* Remove the escaped backtick from the opener. */ + mark->beg++; + } + if(mark->flags & MD_MARK_POTENTIAL_OPENER) md_mark_chain_append(ctx, &BACKTICK_OPENERS, mark_index); }