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 f99ad2e8c4c13f807db1b31df2cae0278beb3467
parent 5864554ce8d3aa084440ae08c5e293be4e897db8
Author: Martin Mitas <mity@morous.org>
Date:   Sat,  8 Oct 2016 23:22:24 +0200

Fix: Fenced code info string can contain more then just a language name.

Diffstat:
Mmd4c/md4c.c | 17++++++++++++-----
Mmd4c/md4c.h | 5+++++
2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/md4c/md4c.c b/md4c/md4c.c @@ -1720,6 +1720,8 @@ md_process_block(MD_CTX* ctx, const MD_LINE* lines, int n_lines) if(n_lines == 0) return 0; + memset(&det, 0, sizeof(det)); + /* Make sure the processed leaf block lives in the proper block quote * nesting level. */ MD_CHECK(md_process_blockquote_nesting(ctx, lines[0].quote_level)); @@ -1740,18 +1742,23 @@ md_process_block(MD_CTX* ctx, const MD_LINE* lines, int n_lines) break; case MD_LINE_INDENTEDCODE: - det.code.lang = NULL; - det.code.lang_size = 0; block_type = MD_BLOCK_CODE; break; case MD_LINE_FENCEDCODE: block_type = MD_BLOCK_CODE; if(ctx->code_fence_info_beg < ctx->code_fence_info_end) - det.code.lang = STR(ctx->code_fence_info_beg); + det.code.info = STR(ctx->code_fence_info_beg); else - det.code.lang = NULL; - det.code.lang_size = ctx->code_fence_info_end - ctx->code_fence_info_beg; + det.code.info = NULL; + det.code.info_size = ctx->code_fence_info_end - ctx->code_fence_info_beg; + + det.code.lang = det.code.info; + det.code.lang_size = 0; + while(det.code.lang_size < det.code.info_size + && !ISWHITESPACE_(det.code.lang[det.code.lang_size])) + det.code.lang_size++; + break; case MD_LINE_TEXT: diff --git a/md4c/md4c.h b/md4c/md4c.h @@ -135,6 +135,11 @@ struct MD_BLOCK_H_DETAIL_tag { /* Detailed info for MD_BLOCK_CODE. */ typedef struct MD_BLOCK_CODE_DETAIL_tag MD_BLOCK_CODE_DETAIL; struct MD_BLOCK_CODE_DETAIL_tag { + /* Complete "info string" */ + const MD_CHAR* info; /* Not zero-terminated, use lang_size. */ + MD_SIZE info_size; + + /* Language portion of the info string. */ const MD_CHAR* lang; /* Not zero-terminated, use lang_size. */ MD_SIZE lang_size; };