cmark

My personal build of CMark ✏️

Commit
8a71de7d058592b05c7f74424d2a2efbeab8ddc2
Parent
68c3a91166347a32a57fb81223750a63cfd92105
Author
John MacFarlane <jgm@berkeley.edu>
Date

Improve rendering of commonmark code spans with spaces.

Closes #316.

Diffstat

1 file changed, 9 insertions, 1 deletion

Status File Name N° Changes Insertions Deletions
Modified src/commonmark.c 10 9 1
diff --git a/src/commonmark.c b/src/commonmark.c
@@ -182,6 +182,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
   char *emph_delim;
   bool first_in_list_item;
   bufsize_t marker_width;
+  bool has_nonspace;
   bool allow_wrap = renderer->width > 0 && !(CMARK_OPT_NOBREAKS & options) &&
                     !(CMARK_OPT_HARDBREAKS & options);
 
@@ -371,9 +372,16 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
     code = cmark_node_get_literal(node);
     code_len = strlen(code);
     numticks = shortest_unused_backtick_sequence(code);
+    has_nonspace = false;
+    for (i=0; i < code_len; i++) {
+      if (code[i] != ' ') {
+        has_nonspace = true;
+        break;
+      }
+    }
     extra_spaces = code_len == 0 ||
 	    code[0] == '`' || code[code_len - 1] == '`' ||
-	    code[0] == ' ' || code[code_len - 1] == ' ';
+	    (has_nonspace && code[0] == ' ' && code[code_len - 1] == ' ');
     for (i = 0; i < numticks; i++) {
       LIT("`");
     }