summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2015-03-29 16:40:48 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2015-03-29 16:40:48 -0700
commite345fd465ac5920cd78315883a76f4bafbaec71f (patch)
tree7b8e6ba0edd8a7d305378fec5ac58a0be9668299
parente63be8475f241cde1f7001252a3039b5c66c3e0f (diff)
commonmark - use fenced code blocks if code starts/ends with blank.
-rw-r--r--src/commonmark.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/commonmark.c b/src/commonmark.c
index 17a89ab..180ff18 100644
--- 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;
}