diff options
author | John MacFarlane <[email protected]> | 2015-12-19 21:15:43 -0800 |
---|---|---|
committer | John MacFarlane <[email protected]> | 2015-12-19 21:18:02 -0800 |
commit | b0a6c472f881a3e0a7b61722fb6fddbcc39e5139 (patch) | |
tree | 511cc8147fef48a302128eae05af1ff37c21d092 /src/node.c | |
parent | 774ac507fc7e86c6fe0d7b16a3c1abaed4849fab (diff) |
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.
Diffstat (limited to 'src/node.c')
-rw-r--r-- | src/node.c | 71 |
1 files changed, 71 insertions, 0 deletions
@@ -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; |