summaryrefslogtreecommitdiff
path: root/src/html.c
diff options
context:
space:
mode:
authorNick Wellnhofer <wellnhofer@aevum.de>2020-01-19 13:46:10 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2020-01-23 08:25:54 -0800
commitf3f50b29d615d2678d8047dc277b108cc5143167 (patch)
treeca3f01f6352d2cc2dd7cfc9c96508b800b8cc510 /src/html.c
parent3ef0718f9f4c9dea5014a8a0e9a67e2366b9374f (diff)
Rearrange struct cmark_node
Introduce multi-purpose data/len members in struct cmark_node. This is mainly used to store literal text for inlines, code and HTML blocks. Move the content strbuf for blocks from cmark_node to cmark_parser. When finalizing nodes that allow inlines (paragraphs and headings), detach the strbuf and store the block content in the node's data/len members. Free the block content after processing inlines. Reduces size of struct cmark_node by 8 bytes.
Diffstat (limited to 'src/html.c')
-rw-r--r--src/html.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/src/html.c b/src/html.c
index f3f4cd1..c69ffb6 100644
--- a/src/html.c
+++ b/src/html.c
@@ -61,7 +61,7 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
case CMARK_NODE_TEXT:
case CMARK_NODE_CODE:
case CMARK_NODE_HTML_INLINE:
- escape_html(html, node->as.literal.data, node->as.literal.len);
+ escape_html(html, node->data, node->len);
break;
case CMARK_NODE_LINEBREAK:
@@ -164,8 +164,7 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
cmark_strbuf_puts(html, "\">");
}
- escape_html(html, node->as.code.literal,
- strlen((char *)node->as.code.literal));
+ escape_html(html, node->data, node->len);
cmark_strbuf_puts(html, "</code></pre>\n");
break;
@@ -174,7 +173,7 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
if (!(options & CMARK_OPT_UNSAFE)) {
cmark_strbuf_puts(html, "<!-- raw HTML omitted -->");
} else {
- cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len);
+ cmark_strbuf_put(html, node->data, node->len);
}
cr(html);
break;
@@ -218,7 +217,7 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
break;
case CMARK_NODE_TEXT:
- escape_html(html, node->as.literal.data, node->as.literal.len);
+ escape_html(html, node->data, node->len);
break;
case CMARK_NODE_LINEBREAK:
@@ -237,7 +236,7 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
case CMARK_NODE_CODE:
cmark_strbuf_puts(html, "<code>");
- escape_html(html, node->as.literal.data, node->as.literal.len);
+ escape_html(html, node->data, node->len);
cmark_strbuf_puts(html, "</code>");
break;
@@ -245,7 +244,7 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
if (!(options & CMARK_OPT_UNSAFE)) {
cmark_strbuf_puts(html, "<!-- raw HTML omitted -->");
} else {
- cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len);
+ cmark_strbuf_put(html, node->data, node->len);
}
break;
@@ -325,7 +324,7 @@ static int S_render_node(cmark_node *node, cmark_event_type ev_type,
char *cmark_render_html(cmark_node *root, int options) {
char *result;
- cmark_strbuf html = CMARK_BUF_INIT(cmark_node_mem(root));
+ cmark_strbuf html = CMARK_BUF_INIT(root->mem);
cmark_event_type ev_type;
cmark_node *cur;
struct render_state state = {&html, NULL};