cmark

My personal build of CMark ✏️

Commit
1880e6535e335f143f9547494def01c13f2f331b
Parent
77f7e7ae8b8f6c42c12e658c7a129429c1ba7bee
Author
John MacFarlane <jgm@berkeley.edu>
Date

Commonmark renderer: always use fences for code (#317).

This solves problems with adjacent code blocks being merged.

Diffstat

1 file changed, 17 insertions, 37 deletions

Status File Name N° Changes Insertions Deletions
Modified src/commonmark.c 54 17 37
diff --git a/src/commonmark.c b/src/commonmark.c
@@ -215,8 +215,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
     break;
 
   case CMARK_NODE_LIST:
-    if (!entering && node->next && (node->next->type == CMARK_NODE_CODE_BLOCK ||
-                                    node->next->type == CMARK_NODE_LIST)) {
+    if (!entering && node->next && (node->next->type == CMARK_NODE_LIST)) {
       // this ensures that a following indented code block or list will be
       // inteprereted correctly.
       CR();
@@ -277,14 +276,6 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
     break;
 
   case CMARK_NODE_CODE_BLOCK:
-    if (entering && node->prev &&
-		    (node->prev->type == CMARK_NODE_CODE_BLOCK)) {
-      // this ensures that consecutive indented code blocks will not
-      // be merged (#317)
-      CR();
-      LIT("<!-- end code block -->");
-      BLANKLINE();
-    }
 
     first_in_list_item = node->prev == NULL && node->parent &&
                          node->parent->type == CMARK_NODE_ITEM;
@@ -297,34 +288,23 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
     fencechar[0] = strchr(info, '`') == NULL ? '`' : '~';
     code = cmark_node_get_literal(node);
     code_len = strlen(code);
-    // use indented form if no info, and code doesn't
-    // begin or end with a blank line, and code isn't
-    // first thing in a list item
-    if (info_len == 0 && (code_len > 2 && !cmark_isspace(code[0]) &&
-                          !(cmark_isspace(code[code_len - 1]) &&
-                            cmark_isspace(code[code_len - 2]))) &&
-        !first_in_list_item) {
-      LIT("    ");
-      cmark_strbuf_puts(renderer->prefix, "    ");
-      OUT(cmark_node_get_literal(node), false, LITERAL);
-      cmark_strbuf_truncate(renderer->prefix, renderer->prefix->size - 4);
-    } else {
-      numticks = longest_backtick_sequence(code) + 1;
-      if (numticks < 3) {
-        numticks = 3;
-      }
-      for (i = 0; i < numticks; i++) {
-        LIT(fencechar);
-      }
-      LIT(" ");
-      OUT(info, false, LITERAL);
-      CR();
-      OUT(cmark_node_get_literal(node), false, LITERAL);
-      CR();
-      for (i = 0; i < numticks; i++) {
-        LIT(fencechar);
-      }
+
+    numticks = longest_backtick_sequence(code) + 1;
+    if (numticks < 3) {
+      numticks = 3;
+    }
+    for (i = 0; i < numticks; i++) {
+      LIT(fencechar);
     }
+    LIT(" ");
+    OUT(info, false, LITERAL);
+    CR();
+    OUT(cmark_node_get_literal(node), false, LITERAL);
+    CR();
+    for (i = 0; i < numticks; i++) {
+      LIT(fencechar);
+    }
+
     BLANKLINE();
     break;