summaryrefslogtreecommitdiff
path: root/src/commonmark.c
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-06-02 11:04:16 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2016-06-02 11:05:17 -0700
commit45bfbcc9d2a82bb79d57aead9e51099e71e187e9 (patch)
tree1625429aab17ca6845399cc9816dc7dac1bd5064 /src/commonmark.c
parente59b38ee67eea5d62066df29edf025f53096f46e (diff)
commonmark renderer: fixed code block as first in list item.
We don't want a blank line before a code block when it's the first thing in a list item.
Diffstat (limited to 'src/commonmark.c')
-rw-r--r--src/commonmark.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/commonmark.c b/src/commonmark.c
index 42a5f19..6862828 100644
--- a/src/commonmark.c
+++ b/src/commonmark.c
@@ -171,6 +171,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
size_t info_len, code_len;
char listmarker[LISTMARKER_SIZE];
char *emph_delim;
+ bool first_in_list_item;
bufsize_t marker_width;
bool allow_wrap = renderer->width > 0 && !(CMARK_OPT_NOBREAKS & options) &&
!(CMARK_OPT_HARDBREAKS & options);
@@ -206,7 +207,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
case CMARK_NODE_LIST:
if (!entering && node->next && (node->next->type == CMARK_NODE_CODE_BLOCK ||
node->next->type == CMARK_NODE_LIST)) {
- // this ensures that a following code block or list will be
+ // this ensures that a following indented code block or list will be
// inteprereted correctly.
CR();
LIT("<!-- end list -->");
@@ -266,7 +267,12 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
break;
case CMARK_NODE_CODE_BLOCK:
- BLANKLINE();
+ first_in_list_item = node->prev == NULL && node->parent &&
+ node->parent->type == CMARK_NODE_ITEM;
+
+ if (!first_in_list_item) {
+ BLANKLINE();
+ }
info = cmark_node_get_fence_info(node);
info_len = safe_strlen(info);
code = cmark_node_get_literal(node);
@@ -277,8 +283,7 @@ static int S_render_node(cmark_renderer *renderer, cmark_node *node,
if (info_len == 0 && (code_len > 2 && !isspace((unsigned char)code[0]) &&
!(isspace((unsigned char)code[code_len - 1]) &&
isspace((unsigned char)code[code_len - 2]))) &&
- !(node->prev == NULL && node->parent &&
- node->parent->type == CMARK_NODE_ITEM)) {
+ !first_in_list_item) {
LIT(" ");
cmark_strbuf_puts(renderer->prefix, " ");
OUT(cmark_node_get_literal(node), false, LITERAL);