diff options
-rw-r--r-- | src/cmark.c | 68 | ||||
-rw-r--r-- | src/cmark.h | 11 | ||||
-rw-r--r-- | src/inlines.c | 15 |
3 files changed, 36 insertions, 58 deletions
diff --git a/src/cmark.c b/src/cmark.c index 05bd7df..8f379bf 100644 --- a/src/cmark.c +++ b/src/cmark.c @@ -24,29 +24,6 @@ unsigned char *cmark_markdown_to_html(unsigned char *text, int len) return result; } -// Free a node_block list and any children. -void cmark_free_blocks(cmark_node_block *e) -{ - cmark_node_block * next; - while (e != NULL) { - cmark_free_inlines(e->inline_content); - strbuf_free(&e->string_content); - if (e->tag == CMARK_BLOCK_FENCED_CODE) { - strbuf_free(&e->as.code.info); - } else if (e->tag == CMARK_BLOCK_DOCUMENT) { - reference_map_free(e->as.document.refmap); - } - if (e->last_child) { - // Splice children into list - e->last_child->next = e->next; - e->next = e->children; - } - next = e->next; - free(e); - e = next; - } -} - // Utility function used by free_inlines static void splice_into_list(cmark_node_inl* e, node_inl* children) { cmark_node_inl * tmp; @@ -168,33 +145,26 @@ inline cmark_node_inl* cmark_make_simple(int t) return e; } -// Append inline list b to the end of inline list a. -// Return pointer to head of new list. -inline cmark_node_inl* cmark_append_inlines(cmark_node_inl* a, cmark_node_inl* b) +// Free a node_block list and any children. +void cmark_free_blocks(cmark_node_block *e) { - if (a == NULL) { // NULL acts like an empty list - return b; - } - cmark_node_inl* cur = a; - while (cur->next != NULL) { - cur = cur->next; + cmark_node_block * next; + while (e != NULL) { + cmark_free_inlines(e->inline_content); + strbuf_free(&e->string_content); + if (e->tag == CMARK_BLOCK_FENCED_CODE) { + strbuf_free(&e->as.code.info); + } else if (e->tag == CMARK_BLOCK_DOCUMENT) { + reference_map_free(e->as.document.refmap); + } + if (e->last_child) { + // Splice children into list + e->last_child->next = e->next; + e->next = e->children; + } + next = e->next; + free(e); + e = next; } - cur->next = b; - return a; } -// Append block list b to the end of block list a. -// Return pointer to head of new list. -inline cmark_node_block* cmark_append_blocks(cmark_node_block* a, cmark_node_block* b) -{ - if (a == NULL) { // NULL acts like an empty list - return b; - } - cmark_node_block* cur = a; - while (cur->next != NULL) { - cur = cur->next; - } - cur->next = b; - b->prev = cur; - return a; -} diff --git a/src/cmark.h b/src/cmark.h index ef9bdfb..65e8cfc 100644 --- a/src/cmark.h +++ b/src/cmark.h @@ -127,12 +127,6 @@ CMARK_EXPORT void cmark_free_inlines(cmark_node_inl* e); CMARK_EXPORT -cmark_node_inl* cmark_append_inlines(cmark_node_inl* a, cmark_node_inl* b); - -CMARK_EXPORT -cmark_node_block* cmark_append_blocks(cmark_node_block* a, cmark_node_block* b); - -CMARK_EXPORT cmark_node_inl *cmark_make_link(cmark_node_inl *label, unsigned char *url, unsigned char *title); CMARK_EXPORT @@ -217,7 +211,6 @@ unsigned char *cmark_markdown_to_html(unsigned char *text, int len); #define BLOCK_REFERENCE_DEF CMARK_BLOCK_REFERENCE_DEF #define free_simple cmark_free_simple #define free_blocks cmark_free_blocks - #define append_simple cmark_append_simple #define make_link cmark_make_link #define make_autolink cmark_make_autolink #define make_str cmark_make_str @@ -228,8 +221,8 @@ unsigned char *cmark_markdown_to_html(unsigned char *text, int len); #define make_emph cmark_make_emph #define make_strong cmark_make_strong #define make_simple cmark_make_simple - #define make_simple cmark_make_simple - #define make_simple cmark_make_simple + #define make_literal cmark_make_literal + #define make_inlines cmark_make_inlines #define doc_parser cmark_doc_parser #define new_doc_parser cmark_new_doc_parser #define free_doc_parser cmark_free_doc_parser diff --git a/src/inlines.c b/src/inlines.c index 0dabbd3..cf07586 100644 --- a/src/inlines.c +++ b/src/inlines.c @@ -101,6 +101,21 @@ static inline chunk take_while(subject* subj, int (*f)(int)) return chunk_dup(&subj->input, startpos, len); } +// Append inline list b to the end of inline list a. +// Return pointer to head of new list. +static inline cmark_node_inl* cmark_append_inlines(cmark_node_inl* a, cmark_node_inl* b) +{ + if (a == NULL) { // NULL acts like an empty list + return b; + } + cmark_node_inl* cur = a; + while (cur->next != NULL) { + cur = cur->next; + } + cur->next = b; + return a; +} + // Try to process a backtick code span that began with a // span of ticks of length openticklength length (already // parsed). Return 0 if you don't find matching closing |