Commit f99ad2e8c4c13f807db1b31df2cae0278beb3467

Martin Mitas 2016-10-08T23:22:24

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

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;
 };