cmark

My personal build of CMark ✏️

Commit
6e25c889cf33a6217a9b4cf37ea1a6361883901b
Parent
06fcdb7592a6106daa52dfe4830373ed735e4053
Author
John MacFarlane <jgm@berkeley.edu>
Date

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.

Diffstat

7 files changed, 17 insertions, 10 deletions

Status File Name N° Changes Insertions Deletions
Modified man/man3/cmark.3 2 1 1
Modified src/blocks.c 2 1 1
Modified src/html.c 3 2 1
Modified src/man.c 4 2 2
Modified src/node.c 11 8 3
Modified src/node.h 1 1 0
Modified src/print.c 4 2 2
diff --git a/man/man3/cmark.3 b/man/man3/cmark.3
@@ -1,4 +1,4 @@
-.TH cmark 3 "December 15, 2014" "LOCAL" "Library Functions Manual"
+.TH cmark 3 "December 16, 2014" "LOCAL" "Library Functions Manual"
 .SH
 NAME
 .PP
diff --git 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
@@ -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, "</code></pre>\n");
 		break;
 
diff --git 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
@@ -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
@@ -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
@@ -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: