From 59fd5633da5395cbd3627af4a2ab855dc43ce1e0 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Tue, 18 Nov 2014 00:12:27 +0100 Subject: Set prev, parent and last_child for inlines --- src/blocks.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/blocks.c') diff --git a/src/blocks.c b/src/blocks.c index cf5e08c..0e68259 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -283,6 +283,19 @@ typedef struct BlockStack { cmark_node *next_sibling; } block_stack; +static void fix_parents(cmark_node *node) { + cmark_node *cur = node->first_child; + if (cur == NULL) { + return; + } + while (cur->next != NULL) { + cur->parent = node; + cur = cur->next; + } + cur->parent = node; + node->last_child = cur; +} + // Walk through cmark_node and all children, recursively, parsing // string content into inline content where appropriate. static void process_inlines(cmark_node* cur, reference_map *refmap) @@ -296,6 +309,7 @@ static void process_inlines(cmark_node* cur, reference_map *refmap) case NODE_ATX_HEADER: case NODE_SETEXT_HEADER: cur->first_child = parse_inlines(&cur->string_content, refmap); + fix_parents(cur); break; default: @@ -817,6 +831,11 @@ cmark_node *cmark_finish(cmark_doc_parser *parser) { finalize_document(parser); strbuf_free(parser->curline); +#if CMARK_DEBUG_NODES + if (cmark_node_check(parser->root)) { + abort(); + } +#endif return parser->root; } -- cgit v1.2.3