From 6e25c889cf33a6217a9b4cf37ea1a6361883901b Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 16 Dec 2014 12:01:19 -0800 Subject: Added 'literal' field to 'code' struct. In the last few commits we were using as.code.fenced and as.literal at the same time for NODE_CODE_BLOCK, which obviously led to problems. --- src/blocks.c | 2 +- src/html.c | 3 ++- src/man.c | 4 ++-- src/node.c | 11 ++++++++--- src/node.h | 1 + src/print.c | 4 ++-- 6 files changed, 16 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/blocks.c b/src/blocks.c index fe43055..4dcd3f4 100644 --- a/src/blocks.c +++ b/src/blocks.c @@ -232,7 +232,7 @@ finalize(cmark_parser *parser, cmark_node* b, int line_number) cmark_strbuf_drop(&b->string_content, firstlinelen + 1); } - b->as.literal = cmark_chunk_buf_detach(&b->string_content); + b->as.code.literal = cmark_chunk_buf_detach(&b->string_content); break; case NODE_HTML: diff --git a/src/html.c b/src/html.c index b5a0950..40b5e94 100644 --- a/src/html.c +++ b/src/html.c @@ -152,7 +152,8 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, void *vstate) cmark_strbuf_puts(html, "\">"); } - escape_html(html, node->as.literal.data, node->as.literal.len); + escape_html(html, node->as.code.literal.data, + node->as.code.literal.len); cmark_strbuf_puts(html, "\n"); break; diff --git a/src/man.c b/src/man.c index e72a121..36a5c99 100644 --- a/src/man.c +++ b/src/man.c @@ -130,8 +130,8 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, void *vstate) case CMARK_NODE_CODE_BLOCK: cr(man); cmark_strbuf_puts(man, ".IP\n.nf\n\\f[C]\n"); - escape_man(man, node->as.literal.data, - node->as.literal.len); + escape_man(man, node->as.code.literal.data, + node->as.code.literal.len); cr(man); cmark_strbuf_puts(man, "\\f[]\n.fi"); cr(man); diff --git a/src/node.c b/src/node.c index 8e74204..1ae5e57 100644 --- a/src/node.c +++ b/src/node.c @@ -42,7 +42,7 @@ void S_free_nodes(cmark_node *e) switch (e->type){ case NODE_CODE_BLOCK: cmark_chunk_free(&e->as.code.info); - cmark_chunk_free(&e->as.literal); + cmark_chunk_free(&e->as.code.literal); break; case NODE_TEXT: case NODE_INLINE_HTML: @@ -183,13 +183,15 @@ cmark_node_get_literal(cmark_node *node) { } switch (node->type) { - case NODE_CODE_BLOCK: case NODE_HTML: case NODE_TEXT: case NODE_INLINE_HTML: case NODE_CODE: return cmark_chunk_to_cstr(&node->as.literal); + case NODE_CODE_BLOCK: + return cmark_chunk_to_cstr(&node->as.code.literal); + default: break; } @@ -204,7 +206,6 @@ cmark_node_set_literal(cmark_node *node, const char *content) { } switch (node->type) { - case NODE_CODE_BLOCK: case NODE_HTML: case NODE_TEXT: case NODE_INLINE_HTML: @@ -212,6 +213,10 @@ cmark_node_set_literal(cmark_node *node, const char *content) { cmark_chunk_set_cstr(&node->as.literal, content); return 1; + case NODE_CODE_BLOCK: + cmark_chunk_set_cstr(&node->as.code.literal, content); + return 1; + default: break; } diff --git a/src/node.h b/src/node.h index 199f020..fb3b667 100644 --- a/src/node.h +++ b/src/node.h @@ -27,6 +27,7 @@ typedef struct { int fence_offset; unsigned char fence_char; cmark_chunk info; + cmark_chunk literal; } cmark_code; typedef struct { diff --git a/src/print.c b/src/print.c index a4654f2..c38271f 100644 --- a/src/print.c +++ b/src/print.c @@ -81,8 +81,8 @@ static void render_nodes(cmark_strbuf* buffer, cmark_node* node, int indent) print_str(buffer, node->as.code.info.data, node->as.code.info.len); cmark_strbuf_putc(buffer, ' '); - print_str(buffer, node->as.literal.data, - node->as.literal.len); + print_str(buffer, node->as.code.literal.data, + node->as.code.literal.len); cmark_strbuf_putc(buffer, '\n'); break; case NODE_HTML: -- cgit v1.2.3