diff options
author | Nick Wellnhofer <wellnhofer@aevum.de> | 2014-11-17 21:04:42 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2014-11-17 21:43:46 -0800 |
commit | 463d64219b2f47c9bfb50d05a7f4d2b2a4293a97 (patch) | |
tree | ee3a2f20b4562a711dae79c9b95116cb0c28bb43 /src/cmark.c | |
parent | 24643bde1d2c79cc512242379868efadf653c1da (diff) |
Switch cmark_node_inl over to cmark_node
Diffstat (limited to 'src/cmark.c')
-rw-r--r-- | src/cmark.c | 67 |
1 files changed, 22 insertions, 45 deletions
diff --git a/src/cmark.c b/src/cmark.c index 328be9d..7cc8e5c 100644 --- a/src/cmark.c +++ b/src/cmark.c @@ -70,14 +70,14 @@ unsigned char *cmark_markdown_to_html(unsigned char *text, int len) blocks = cmark_parse_document(text, len); result = cmark_render_html(blocks); - cmark_free_blocks(blocks); + cmark_free_nodes(blocks); return result; } -// Utility function used by free_inlines -static void splice_into_list(cmark_node_inl* e, node_inl* children) { - cmark_node_inl * tmp; +// Utility function used by cmark_free_nodes +static void splice_into_list(cmark_node* e, cmark_node* children) { + cmark_node * tmp; if (children) { tmp = children; // Find last child @@ -91,43 +91,6 @@ static void splice_into_list(cmark_node_inl* e, node_inl* children) { return ; } -// Free an inline list. Avoid recursion to prevent stack overflows -// on deeply nested structures. -void cmark_free_inlines(cmark_node_inl* e) -{ - node_inl * next; - - while (e != NULL) { - switch (e->tag){ - case CMARK_INL_STRING: - case CMARK_INL_RAW_HTML: - case CMARK_INL_CODE: - cmark_chunk_free(&e->content.literal); - break; - case CMARK_INL_LINEBREAK: - case CMARK_INL_SOFTBREAK: - break; - case CMARK_INL_LINK: - case CMARK_INL_IMAGE: - free(e->content.linkable.url); - free(e->content.linkable.title); - splice_into_list(e, e->content.linkable.label); - break; - case CMARK_INL_EMPH: - case CMARK_INL_STRONG: - splice_into_list(e, e->content.inlines); - break; - default: - fprintf(stderr, "[WARN] (%s:%d) Unknown inline tag %d", - __FILE__, __LINE__, e->tag); - break; - } - next = e->next; - free(e); - e = next; - } -} - unsigned char *cmark_clean_autolink(chunk *url, int is_email) { strbuf buf = GH_BUF_INIT; @@ -144,15 +107,29 @@ unsigned char *cmark_clean_autolink(chunk *url, int is_email) return strbuf_detach(&buf); } -// Free a node_block list and any children. -void cmark_free_blocks(cmark_node *e) +// Free a cmark_node list and any children. +void cmark_free_nodes(cmark_node *e) { cmark_node *next; while (e != NULL) { - cmark_free_inlines(e->inline_content); strbuf_free(&e->string_content); - if (e->type == NODE_FENCED_CODE) { + switch (e->type){ + case NODE_FENCED_CODE: strbuf_free(&e->as.code.info); + break; + case NODE_STRING: + case NODE_INLINE_HTML: + case NODE_INLINE_CODE: + cmark_chunk_free(&e->as.literal); + break; + case NODE_LINK: + case NODE_IMAGE: + free(e->as.link.url); + free(e->as.link.title); + splice_into_list(e, e->as.link.label); + break; + default: + break; } if (e->last_child) { // Splice children into list |