cmark

My personal build of CMark ✏️

Commit
f5a456175cfde7bad10fad96e9fa17d357c8244a
Parent
9858400cefef4d5ef96e19caeb554cd0b283d12e
Author
John MacFarlane <fiddlosopher@gmail.com>
Date

Adjusted HTML output for fenced code to match #71 change.

Diffstat

2 files changed, 7 insertions, 6 deletions

Status File Name N° Changes Insertions Deletions
Modified js/stmd.js 7 4 3
Modified src/html.c 6 3 3
diff --git a/js/stmd.js b/js/stmd.js
@@ -1478,9 +1478,10 @@ var renderBlock = function(block, in_tight_list) {
     case 'FencedCode':
       info_words = block.info.split(/ +/);
       attr = info_words.length === 0 || info_words[0].length === 0 ?
-                   [] : [['class',this.escape(info_words[0],true)]];
-      return inTags('pre', attr,
-              inTags('code', [], this.escape(block.string_content)));
+                   [] : [['class','language-' +
+                                   this.escape(info_words[0],true)]];
+      return inTags('pre', [],
+              inTags('code', attr, this.escape(block.string_content)));
     case 'HtmlBlock':
       return block.string_content;
     case 'ReferenceDef':
diff --git a/src/html.c b/src/html.c
@@ -156,15 +156,15 @@ extern int blocks_to_html(block* b, bstring* result, bool tight)
     case fenced_code:
       escaped = escape_html(b->string_content, false);
       cr(html);
-      bformata(html, "<pre");
+      bformata(html, "<pre><code");
       if (blength(b->attributes.fenced_code_data.info) > 0) {
         escaped2 = escape_html(b->attributes.fenced_code_data.info, true);
         info_words = bsplit(escaped2, ' ');
-        bformata(html, " class=\"%s\"", info_words->entry[0]->data);
+        bformata(html, " class=\"language-%s\"", info_words->entry[0]->data);
         bdestroy(escaped2);
         bstrListDestroy(info_words);
       }
-      bformata(html, "><code>%s</code></pre>", escaped->data);
+      bformata(html, ">%s</code></pre>", escaped->data);
       cr(html);
       bdestroy(escaped);
       break;