diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-03-29 20:32:15 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-03-29 20:32:15 -0700 |
commit | 07abc70323fe35f711a650b39472e0ac5af96185 (patch) | |
tree | 2ccdba82d20edad4a8cc6fa0884c40aee857cb9f | |
parent | 86263adc7ee25ca727c770586fe1a67e41ad8f10 (diff) |
commonmark renderer - improved tight list detection.
-rw-r--r-- | src/commonmark.c | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/commonmark.c b/src/commonmark.c index c94cf9a..83a6602 100644 --- a/src/commonmark.c +++ b/src/commonmark.c @@ -233,6 +233,19 @@ shortest_unused_backtick_sequence(cmark_chunk *code) return i; } +// if node is a block node, returns node. +// otherwise returns first block-level node that is an ancestor of node. +static cmark_node* +get_containing_block(cmark_node *node) +{ + while (node && + (node->type < CMARK_NODE_FIRST_BLOCK || + node->type > CMARK_NODE_LAST_BLOCK)) { + node = node->parent; + } + return node; +} + static int S_render_node(cmark_node *node, cmark_event_type ev_type, struct render_state *state) @@ -255,11 +268,14 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, // a following list. if (!(node->type == CMARK_NODE_ITEM && node->prev == NULL && entering)) { - state->in_tight_list_item = - (node->type == CMARK_NODE_ITEM && - cmark_node_get_list_tight(node->parent)) || - (node->parent && node->parent->type == CMARK_NODE_ITEM && - cmark_node_get_list_tight(node->parent->parent)); + tmp = get_containing_block(node); + state->in_tight_list_item = + (tmp->type == CMARK_NODE_ITEM && + cmark_node_get_list_tight(tmp->parent)) || + (tmp && + tmp->parent && + tmp->parent->type == CMARK_NODE_ITEM && + cmark_node_get_list_tight(tmp->parent->parent)); } switch (node->type) { |