cmark

My personal build of CMark ✏️

Commit
e345fd465ac5920cd78315883a76f4bafbaec71f
Parent
e63be8475f241cde1f7001252a3039b5c66c3e0f
Author
John MacFarlane <jgm@berkeley.edu>
Date

commonmark - use fenced code blocks if code starts/ends with blank.

Diffstat

1 file changed, 9 insertions, 3 deletions

Status File Name N° Changes Insertions Deletions
Modified src/commonmark.c 12 9 3
diff --git a/src/commonmark.c b/src/commonmark.c
@@ -344,15 +344,21 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
 	case CMARK_NODE_CODE_BLOCK:
 		blankline(state);
 		info = cmark_node_get_fence_info(node);
-		if (info == NULL || strlen(info) == 0) {
-			// use indented form if no info
+		code = &node->as.code.literal;
+		if ((info == NULL || strlen(info) == 0) &&
+		    (code->len > 2 &&
+		     !isspace(code->data[0]) &&
+		     !(isspace(code->data[code->len - 1]) &&
+		       isspace(code->data[code->len - 2])))) {
+			// use indented form if no info and code doesn't
+			// begin or end with a blank line
 			lit(state, "    ", false);
 			cmark_strbuf_puts(state->prefix, "    ");
 			out(state, node->as.code.literal, false, LITERAL);
 			cmark_strbuf_truncate(state->prefix,
 					      state->prefix->size - 4);
 		} else {
-			numticks = longest_backtick_sequence(&node->as.code.literal) + 1;
+			numticks = longest_backtick_sequence(code) + 1;
 			if (numticks < 3) {
 				numticks = 3;
 			}