summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-12-14 13:49:53 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2014-12-14 14:03:57 -0800
commit37554bbb7901b7116e1a5006f331968444141b76 (patch)
tree9307d76a0c83f2e36158269d15f72fd565dd7c56
parent1014764a109e7f8f47d466080962f5f344287277 (diff)
Use as.literal instead of string_content for HTML and code blocks.
This is for consistency with the other types of nodes that have literal strings as contents.
-rw-r--r--man/man3/cmark.323
-rw-r--r--src/blocks.c8
-rw-r--r--src/html.c5
-rw-r--r--src/node.c7
4 files changed, 10 insertions, 33 deletions
diff --git a/man/man3/cmark.3 b/man/man3/cmark.3
index 0a281ed..cdfcfa5 100644
--- a/man/man3/cmark.3
+++ b/man/man3/cmark.3
@@ -102,18 +102,6 @@ way, for example, turning all level\-3 headers into regular paragraphs.
.IP
.nf
\f[C]
-void
-usage_example(cmark_node *root) {
- cmark_event_type ev_type;
- cmark_iter *iter = cmark_iter_new(root);
-
- while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
- cmark_node *cur = cmark_iter_get_node(iter);
- // Do something with `cur` and `ev_type`
- }
-
- cmark_iter_free(iter);
-}
\f[]
.fi
@@ -314,7 +302,6 @@ Simple interface:
.IP
.nf
\f[C]
-cmark_node *document = cmark_parse_document("Hello *world*", 12);
\f[]
.fi
.PP
@@ -322,16 +309,6 @@ Streaming interface:
.IP
.nf
\f[C]
-cmark_parser *parser = cmark_parser_new();
-FILE *fp = fopen("myfile.md", "r");
-while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
- cmark_parser_feed(parser, buffer, bytes);
- if (bytes < sizeof(buffer)) {
- break;
- }
-}
-document = cmark_parser_finish(parser);
-cmark_parser_free(parser);
\f[]
.fi
diff --git a/src/blocks.c b/src/blocks.c
index 7648c96..18a6536 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -215,7 +215,6 @@ finalize(cmark_parser *parser, cmark_node* b, int line_number)
if (!b->as.code.fenced) { // indented code
remove_trailing_blank_lines(&b->string_content);
strbuf_putc(&b->string_content, '\n');
- break;
} else {
// first line of contents becomes info
@@ -231,8 +230,13 @@ finalize(cmark_parser *parser, cmark_node* b, int line_number)
strbuf_trim(&b->as.code.info);
strbuf_unescape(&b->as.code.info);
- break;
}
+ b->as.literal = chunk_buf_detach(&b->string_content);
+ break;
+
+ case NODE_HTML:
+ b->as.literal = chunk_buf_detach(&b->string_content);
+ break;
case NODE_LIST: // determine tight/loose status
b->as.list.tight = true; // tight by default
diff --git a/src/html.c b/src/html.c
index e733a48..23812df 100644
--- a/src/html.c
+++ b/src/html.c
@@ -153,14 +153,13 @@ S_render_node(cmark_node *node, cmark_event_type ev_type, void *vstate)
strbuf_puts(html, "\">");
}
- escape_html(html, node->string_content.ptr, node->string_content.size);
+ escape_html(html, node->as.literal.data, node->as.literal.len);
strbuf_puts(html, "</code></pre>\n");
break;
case CMARK_NODE_HTML:
cr(html);
- strbuf_put(html, node->string_content.ptr,
- node->string_content.size);
+ strbuf_put(html, node->as.literal.data, node->as.literal.len);
break;
case CMARK_NODE_HRULE:
diff --git a/src/node.c b/src/node.c
index 276ed46..d74b1fc 100644
--- a/src/node.c
+++ b/src/node.c
@@ -42,10 +42,12 @@ void S_free_nodes(cmark_node *e)
switch (e->type){
case NODE_CODE_BLOCK:
strbuf_free(&e->as.code.info);
+ chunk_free(&e->as.literal);
break;
case NODE_TEXT:
case NODE_INLINE_HTML:
case NODE_CODE:
+ case NODE_HTML:
chunk_free(&e->as.literal);
break;
case NODE_LINK:
@@ -183,8 +185,6 @@ cmark_node_get_string_content(cmark_node *node) {
switch (node->type) {
case NODE_CODE_BLOCK:
case NODE_HTML:
- return strbuf_cstr(&node->string_content);
-
case NODE_TEXT:
case NODE_INLINE_HTML:
case NODE_CODE:
@@ -206,9 +206,6 @@ cmark_node_set_string_content(cmark_node *node, const char *content) {
switch (node->type) {
case NODE_CODE_BLOCK:
case NODE_HTML:
- strbuf_sets(&node->string_content, content);
- return 1;
-
case NODE_TEXT:
case NODE_INLINE_HTML:
case NODE_CODE: