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 789a5b71789d66db319dd2e6eebc5ca39e697edb
parent 1a2477952a4f751fb320f08cd011a2a09ac5e48e
Author: Martin Mitas <mity@morous.org>
Date:   Sun, 20 Nov 2016 00:10:41 +0100

Fix detection of link label with escapes and new lines.

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

diff --git a/md4c/md4c.c b/md4c/md4c.c @@ -1215,10 +1215,10 @@ md_is_link_label(MD_CTX* ctx, const MD_LINE* lines, int n_lines, OFF beg, while(off < line_end) { if(CH(off) == _T('\\') && off < ctx->size && (ISPUNCT(off+1) || ISNEWLINE(off+1))) { - off++; if(contents_end == 0) contents_beg = off; contents_end = off + 2; + off += 2; } else if(CH(off) == _T('[')) { return -1; } else if(CH(off) == _T(']')) { @@ -1234,21 +1234,29 @@ md_is_link_label(MD_CTX* ctx, const MD_LINE* lines, int n_lines, OFF beg, return -1; } } else { - if(contents_end == 0) { - contents_beg = off; - *p_beg_line_index = line_index; + int codepoint; + SZ char_size; + + codepoint = md_decode_unicode(ctx->text, off, ctx->size, &char_size); + if(!ISUNICODEWHITESPACE_(codepoint)) { + if(contents_end == 0) { + contents_beg = off; + *p_beg_line_index = line_index; + } + contents_end = off + char_size; } - contents_end = off + 1; + + off += char_size; } len++; if(len > 999) return -1; - off++; } line_index++; len++; + off = lines[line_index].beg; } return -1;