diff options
-rw-r--r-- | src/html.c | 26 | ||||
-rw-r--r-- | src/node.c | 12 | ||||
-rw-r--r-- | src/node.h | 4 | ||||
-rw-r--r-- | src/xml.c | 8 |
4 files changed, 24 insertions, 26 deletions
@@ -179,17 +179,16 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type, cr(html); break; - case CMARK_NODE_CUSTOM_BLOCK: + case CMARK_NODE_CUSTOM_BLOCK: { + unsigned char *block = entering ? node->as.custom.on_enter : + node->as.custom.on_exit; cr(html); - if (entering) { - cmark_strbuf_put(html, node->as.custom.on_enter.data, - node->as.custom.on_enter.len); - } else { - cmark_strbuf_put(html, node->as.custom.on_exit.data, - node->as.custom.on_exit.len); + if (block) { + cmark_strbuf_puts(html, (char *)block); } cr(html); break; + } case CMARK_NODE_THEMATIC_BREAK: cr(html); @@ -250,15 +249,14 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type, } break; - case CMARK_NODE_CUSTOM_INLINE: - if (entering) { - cmark_strbuf_put(html, node->as.custom.on_enter.data, - node->as.custom.on_enter.len); - } else { - cmark_strbuf_put(html, node->as.custom.on_exit.data, - node->as.custom.on_exit.len); + case CMARK_NODE_CUSTOM_INLINE: { + unsigned char *block = entering ? node->as.custom.on_enter : + node->as.custom.on_exit; + if (block) { + cmark_strbuf_puts(html, (char *)block); } break; + } case CMARK_NODE_STRONG: if (entering) { @@ -125,8 +125,8 @@ static void S_free_nodes(cmark_node *e) { break; case CMARK_NODE_CUSTOM_BLOCK: case CMARK_NODE_CUSTOM_INLINE: - cmark_chunk_free(NODE_MEM(e), &e->as.custom.on_enter); - cmark_chunk_free(NODE_MEM(e), &e->as.custom.on_exit); + NODE_MEM(e)->free(e->as.custom.on_enter); + NODE_MEM(e)->free(e->as.custom.on_exit); break; default: break; @@ -571,7 +571,7 @@ const char *cmark_node_get_on_enter(cmark_node *node) { switch (node->type) { case CMARK_NODE_CUSTOM_INLINE: case CMARK_NODE_CUSTOM_BLOCK: - return cmark_chunk_to_cstr(NODE_MEM(node), &node->as.custom.on_enter); + return node->as.custom.on_enter ? (char *)node->as.custom.on_enter : ""; default: break; } @@ -587,7 +587,7 @@ int cmark_node_set_on_enter(cmark_node *node, const char *on_enter) { switch (node->type) { case CMARK_NODE_CUSTOM_INLINE: case CMARK_NODE_CUSTOM_BLOCK: - cmark_chunk_set_cstr(NODE_MEM(node), &node->as.custom.on_enter, on_enter); + cmark_set_cstr(NODE_MEM(node), &node->as.custom.on_enter, on_enter); return 1; default: break; @@ -604,7 +604,7 @@ const char *cmark_node_get_on_exit(cmark_node *node) { switch (node->type) { case CMARK_NODE_CUSTOM_INLINE: case CMARK_NODE_CUSTOM_BLOCK: - return cmark_chunk_to_cstr(NODE_MEM(node), &node->as.custom.on_exit); + return node->as.custom.on_exit ? (char *)node->as.custom.on_exit : ""; default: break; } @@ -620,7 +620,7 @@ int cmark_node_set_on_exit(cmark_node *node, const char *on_exit) { switch (node->type) { case CMARK_NODE_CUSTOM_INLINE: case CMARK_NODE_CUSTOM_BLOCK: - cmark_chunk_set_cstr(NODE_MEM(node), &node->as.custom.on_exit, on_exit); + cmark_set_cstr(NODE_MEM(node), &node->as.custom.on_exit, on_exit); return 1; default: break; @@ -42,8 +42,8 @@ typedef struct { } cmark_link; typedef struct { - cmark_chunk on_enter; - cmark_chunk on_exit; + unsigned char *on_enter; + unsigned char *on_exit; } cmark_custom; enum cmark_node__internal_flags { @@ -110,12 +110,12 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type, case CMARK_NODE_CUSTOM_BLOCK: case CMARK_NODE_CUSTOM_INLINE: cmark_strbuf_puts(xml, " on_enter=\""); - escape_xml(xml, node->as.custom.on_enter.data, - node->as.custom.on_enter.len); + escape_xml(xml, node->as.custom.on_enter, + strlen((char *)node->as.custom.on_enter)); cmark_strbuf_putc(xml, '"'); cmark_strbuf_puts(xml, " on_exit=\""); - escape_xml(xml, node->as.custom.on_exit.data, - node->as.custom.on_exit.len); + escape_xml(xml, node->as.custom.on_exit, + strlen((char *)node->as.custom.on_exit)); cmark_strbuf_putc(xml, '"'); break; case CMARK_NODE_LINK: |