cmark

Unnamed repository; edit this file 'description' to name the repository.

commit e345fd465ac5920cd78315883a76f4bafbaec71f
parent e63be8475f241cde1f7001252a3039b5c66c3e0f
Author: John MacFarlane <jgm@berkeley.edu>
Date:   Sun, 29 Mar 2015 16:40:48 -0700

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

Diffstat:
Msrc/commonmark.c | 12+++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
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;
 			}