Fix: Fenced code info string can contain more then just a language name.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
diff --git a/md4c/md4c.c b/md4c/md4c.c
index e0bf8ce..7a11ac3 100644
--- 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
index 15b822d..929a9ee 100644
--- 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;
};