From b0a6c472f881a3e0a7b61722fb6fddbcc39e5139 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 19 Dec 2015 21:15:43 -0800 Subject: Changed API for CUSTOM_BLOCK and CUSTOM_INLINE. Instead of using their `as.literal` content, we now give each custom node *two* literal fields, one to be printed on entering the node (before rendering the children, if any), the other on exiting (after rendering children). This gives us the flexibility to have custom nodes with children. --- src/node.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'src/node.c') diff --git a/src/node.c b/src/node.c index 10cd99d..6c82a53 100644 --- a/src/node.c +++ b/src/node.c @@ -113,6 +113,11 @@ static void S_free_nodes(cmark_node *e) { cmark_chunk_free(&e->as.link.url); cmark_chunk_free(&e->as.link.title); break; + case CMARK_NODE_CUSTOM_BLOCK: + case CMARK_NODE_CUSTOM_INLINE: + cmark_chunk_free(&e->as.custom.on_enter); + cmark_chunk_free(&e->as.custom.on_exit); + break; default: break; } @@ -528,6 +533,72 @@ int cmark_node_set_title(cmark_node *node, const char *title) { return 0; } +const char *cmark_node_get_on_enter(cmark_node *node) { + if (node == NULL) { + return NULL; + } + + switch (node->type) { + case CMARK_NODE_CUSTOM_INLINE: + case CMARK_NODE_CUSTOM_BLOCK: + return cmark_chunk_to_cstr(&node->as.custom.on_enter); + default: + break; + } + + return NULL; +} + +int cmark_node_set_on_enter(cmark_node *node, const char *on_enter) { + if (node == NULL) { + return 0; + } + + switch (node->type) { + case CMARK_NODE_CUSTOM_INLINE: + case CMARK_NODE_CUSTOM_BLOCK: + cmark_chunk_set_cstr(&node->as.custom.on_enter, on_enter); + return 1; + default: + break; + } + + return 0; +} + +const char *cmark_node_get_on_exit(cmark_node *node) { + if (node == NULL) { + return NULL; + } + + switch (node->type) { + case CMARK_NODE_CUSTOM_INLINE: + case CMARK_NODE_CUSTOM_BLOCK: + return cmark_chunk_to_cstr(&node->as.custom.on_exit); + default: + break; + } + + return NULL; +} + +int cmark_node_set_on_exit(cmark_node *node, const char *on_exit) { + if (node == NULL) { + return 0; + } + + switch (node->type) { + case CMARK_NODE_CUSTOM_INLINE: + case CMARK_NODE_CUSTOM_BLOCK: + cmark_chunk_set_cstr(&node->as.custom.on_exit, on_exit); + return 1; + default: + break; + } + + return 0; +} + int cmark_node_get_start_line(cmark_node *node) { if (node == NULL) { return 0; -- cgit v1.2.3