From 759e03748a368be8b209dfd113441c05e1a5dcc0 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer
Date: Thu, 20 Nov 2014 13:02:53 +0100
Subject: More tree hierarchy checks and tests
---
src/node.c | 11 +++++++++++
1 file changed, 11 insertions(+)
(limited to 'src')
diff --git a/src/node.c b/src/node.c
index 624baad..4317dd4 100644
--- a/src/node.c
+++ b/src/node.c
@@ -348,6 +348,17 @@ S_is_inline(cmark_node *node) {
static bool
S_can_contain(cmark_node *node, cmark_node *child)
{
+ cmark_node *cur;
+
+ // Verify that child is not an ancestor of node or equal to node.
+ cur = node;
+ do {
+ if (cur == child) {
+ return false;
+ }
+ cur = cur->parent;
+ } while (cur != NULL);
+
if (child->type == CMARK_NODE_DOCUMENT) {
return false;
}
--
cgit v1.2.3
From 32be14c39f67eedf356adc4f673b66479b717c7c Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer
Date: Thu, 20 Nov 2014 15:17:33 +0100
Subject: Set defaults for new headers and lists
---
src/node.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
(limited to 'src')
diff --git a/src/node.c b/src/node.c
index 4317dd4..bb9cacc 100644
--- a/src/node.c
+++ b/src/node.c
@@ -11,6 +11,25 @@ cmark_node*
cmark_node_new(cmark_node_type type) {
cmark_node *node = (cmark_node *)calloc(1, sizeof(*node));
node->type = type;
+
+ switch (node->type) {
+ case CMARK_NODE_ATX_HEADER:
+ case CMARK_NODE_SETEXT_HEADER:
+ node->as.header.level = 1;
+ break;
+
+ case CMARK_NODE_LIST: {
+ cmark_list *list = &node->as.list;
+ list->list_type = CMARK_BULLET_LIST;
+ list->start = 1;
+ list->tight = false;
+ break;
+ }
+
+ default:
+ break;
+ }
+
return node;
}
--
cgit v1.2.3
From 92a4d4cb4eb4a6103f68646a38f8caa29d6df3e3 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer
Date: Sat, 22 Nov 2014 15:41:40 +0100
Subject: Fix and test node_check
---
src/blocks.c | 2 +-
src/node.c | 55 ++++++++++++++++++++++++++++++-------------------------
src/node.h | 4 +++-
3 files changed, 34 insertions(+), 27 deletions(-)
(limited to 'src')
diff --git a/src/blocks.c b/src/blocks.c
index 58162b5..ab9f667 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -818,7 +818,7 @@ cmark_node *cmark_finish(cmark_doc_parser *parser)
finalize_document(parser);
strbuf_free(parser->curline);
#if CMARK_DEBUG_NODES
- if (cmark_node_check(parser->root)) {
+ if (cmark_node_check(parser->root, stderr)) {
abort();
}
#endif
diff --git a/src/node.c b/src/node.c
index bb9cacc..a79dd82 100644
--- a/src/node.c
+++ b/src/node.c
@@ -558,58 +558,63 @@ cmark_node_append_child(cmark_node *node, cmark_node *child)
}
static void
-S_print_error(cmark_node *node, const char *elem)
+S_print_error(FILE *out, cmark_node *node, const char *elem)
{
- fprintf(stderr, "Invalid '%s' in node type %s at %d:%d\n", elem,
+ if (out == NULL) {
+ return;
+ }
+ fprintf(out, "Invalid '%s' in node type %s at %d:%d\n", elem,
S_type_string(node), node->start_line, node->start_column);
}
int
-cmark_node_check(cmark_node *node)
+cmark_node_check(cmark_node *node, FILE *out)
{
- cmark_node *cur = node;
+ cmark_node *cur;
int errors = 0;
- while (cur) {
+ if (!node) {
+ return 0;
+ }
+
+ cur = node;
+ while (true) {
if (cur->first_child) {
if (cur->first_child->parent != cur) {
- S_print_error(cur->first_child, "parent");
+ S_print_error(out, cur->first_child, "parent");
cur->first_child->parent = cur;
++errors;
}
cur = cur->first_child;
+ continue;
+ }
+
+ next_sibling:
+ if (cur == node) {
+ break;
}
- else if (cur->next) {
+ if (cur->next) {
if (cur->next->prev != cur) {
- S_print_error(cur->next, "prev");
+ S_print_error(out, cur->next, "prev");
cur->next->prev = cur;
++errors;
}
if (cur->next->parent != cur->parent) {
- S_print_error(cur->next, "parent");
+ S_print_error(out, cur->next, "parent");
cur->next->parent = cur->parent;
++errors;
}
cur = cur->next;
+ continue;
}
- else {
- if (cur->parent->last_child != cur) {
- S_print_error(cur->parent, "last_child");
- cur->parent->last_child = cur;
- ++errors;
- }
- cmark_node *ancestor = cur->parent;
- cur = NULL;
-
- while (ancestor != node->parent) {
- if (ancestor->next) {
- cur = ancestor->next;
- break;
- }
- ancestor = ancestor->parent;
- }
+ if (cur->parent->last_child != cur) {
+ S_print_error(out, cur->parent, "last_child");
+ cur->parent->last_child = cur;
+ ++errors;
}
+ cur = cur->parent;
+ goto next_sibling;
}
return errors;
diff --git a/src/node.h b/src/node.h
index 2d7f0a1..d1245a5 100644
--- a/src/node.h
+++ b/src/node.h
@@ -5,6 +5,8 @@
extern "C" {
#endif
+#include
+
#include "cmark.h"
#include "buffer.h"
#include "chunk.h"
@@ -62,7 +64,7 @@ struct cmark_node {
};
CMARK_EXPORT int
-cmark_node_check(cmark_node *node);
+cmark_node_check(cmark_node *node, FILE *out);
#ifdef __cplusplus
}
--
cgit v1.2.3
From a4b54c861e384e5574eda36d7b4bb050322b1c34 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer
Date: Wed, 19 Nov 2014 20:23:59 +0100
Subject: Fix debug flags
---
src/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src')
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index dbe53a5..71f45a7 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -64,7 +64,7 @@ set_target_properties(${PROGRAM} PROPERTIES
COMPILE_FLAGS -DCMARK_STATIC_DEFINE)
# Check integrity of node structure when compiled as debug:
-set(CMAKE_C_FLAGS_DEBUG "-DCMARK_DEBUG_NODES")
+set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DCMARK_DEBUG_NODES")
if (${CMAKE_MAJOR_VERSION} GREATER 1 AND ${CMAKE_MINOR_VERSION} GREATER 8)
set(CMAKE_C_VISIBILITY_PRESET hidden)
--
cgit v1.2.3
From 1cf1ec9a8f893a41910a300d9d8f1e6c20288287 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer
Date: Wed, 19 Nov 2014 20:24:08 +0100
Subject: Stackless HTML rendering
Now that every node has a parent pointer, it's possible to implement
the HTML rendering functions without render stacks and any dynamic
memory allocations.
This commit also adds some minor optimizations that eliminate some
strbuf_put* calls for the common case and avoid printf for headers.
---
src/html/html.c | 463 +++++++++++++++++++++++++++-----------------------------
1 file changed, 226 insertions(+), 237 deletions(-)
(limited to 'src')
diff --git a/src/html/html.c b/src/html/html.c
index 76d488a..96fce66 100644
--- a/src/html/html.c
+++ b/src/html/html.c
@@ -7,58 +7,12 @@
#include "cmark.h"
#include "node.h"
#include "buffer.h"
-#include "debug.h"
#include "html/houdini.h"
-typedef struct RenderStack {
- struct RenderStack *previous;
- const char* literal;
- cmark_node* next_sibling;
- bool tight;
- bool trim;
-} render_stack;
+// Functions to convert cmark_nodes to HTML strings.
-static void free_render_stack(render_stack * rstack)
-{
- render_stack * tempstack;
- while (rstack) {
- tempstack = rstack;
- rstack = rstack->previous;
- free(tempstack);
- }
-}
-
-static render_stack* push_render_stack(render_stack* rstack,
- cmark_node* node,
- const char* literal)
-{
- render_stack* newstack;
- newstack = (render_stack*)malloc(sizeof(render_stack));
- if (newstack == NULL) {
- return NULL;
- }
- newstack->previous = rstack;
- newstack->next_sibling = node;
- newstack->literal = literal;
- newstack->tight = false;
- newstack->trim = false;
- return newstack;
-}
-
-static render_stack* pop_render_stack(render_stack* rstack)
-{
- render_stack* top = rstack;
-
- if (rstack == NULL) {
- return NULL;
- }
- rstack = rstack->previous;
- top->previous = NULL;
- free_render_stack(top);
- return rstack;
-}
-
-// Functions to convert cmark_node and inline lists to HTML strings.
+static bool
+finish_node(strbuf *html, cmark_node *node, bool tight);
static void escape_html(strbuf *dest, const unsigned char *source, int length)
{
@@ -82,65 +36,163 @@ static inline void cr(strbuf *html)
strbuf_putc(html, '\n');
}
-// Convert an inline list to HTML. Returns 0 on success, and sets result.
-static void inlines_to_plain_html(strbuf *html, cmark_node* ils)
+// Convert the inline children of a node to a plain string.
+static void inlines_to_plain_html(strbuf *html, cmark_node* node)
{
- cmark_node* children;
- bool visit_children;
- render_stack* rstack = NULL;
+ cmark_node* cur = node->first_child;
- while(ils != NULL) {
- visit_children = false;
- switch(ils->type) {
+ if (cur == NULL) {
+ return;
+ }
+
+ while (true) {
+ switch(cur->type) {
case NODE_STRING:
case NODE_INLINE_CODE:
case NODE_INLINE_HTML:
- escape_html(html, ils->as.literal.data, ils->as.literal.len);
+ escape_html(html, cur->as.literal.data, cur->as.literal.len);
break;
case NODE_LINEBREAK:
case NODE_SOFTBREAK:
- strbuf_putc(html, '\n');
+ strbuf_putc(html, ' ');
break;
- case NODE_LINK:
- case NODE_IMAGE:
- case NODE_STRONG:
- case NODE_EMPH:
- children = ils->first_child;
- visit_children = true;
- rstack = push_render_stack(rstack, ils->next, "");
- break;
default:
break;
}
- if (visit_children) {
- ils = children;
- } else {
- ils = ils->next;
+
+ if (cur->first_child) {
+ cur = cur->first_child;
+ continue;
}
- while (ils == NULL && rstack != NULL) {
- strbuf_puts(html, rstack->literal);
- ils = rstack->next_sibling;
- rstack = pop_render_stack(rstack);
+
+ next_sibling:
+ if (cur->next) {
+ cur = cur->next;
+ continue;
}
+ cur = cur->parent;
+ if (cur == node) {
+ break;
+ }
+ goto next_sibling;
}
-
- free_render_stack(rstack);
}
-// Convert an inline list to HTML. Returns 0 on success, and sets result.
-static void inlines_to_html(strbuf *html, cmark_node* ils)
+// Convert a cmark_node to HTML.
+static void node_to_html(strbuf *html, cmark_node *node)
{
+ cmark_node *cur;
+ char start_header[] = "";
+ bool tight = false;
bool visit_children;
- render_stack* rstack = NULL;
- while(ils != NULL) {
- visit_children = false;
- switch(ils->type) {
+ if (node == NULL) {
+ return;
+ }
+
+ cur = node;
+ while (true) {
+ // Only NODE_IMAGE wants to skip its children.
+ visit_children = true;
+
+ switch(cur->type) {
+ case NODE_DOCUMENT:
+ break;
+
+ case NODE_PARAGRAPH:
+ if (!tight) {
+ cr(html);
+ strbuf_puts(html, "");
+ }
+ break;
+
+ case NODE_BQUOTE:
+ cr(html);
+ strbuf_puts(html, "
\n");
+ // BQUOTE doesn't use any of the 'as' structs,
+ // so the 'list' member can be used to store the
+ // current value of 'tight'.
+ cur->as.list.tight = tight;
+ tight = false;
+ break;
+
+ case NODE_LIST_ITEM:
+ cr(html);
+ strbuf_puts(html, "");
+ break;
+
+ case NODE_LIST: {
+ cmark_list *list = &cur->as.list;
+ bool tmp;
+
+ // make sure a list starts at the beginning of the line:
+ cr(html);
+
+ if (list->list_type == CMARK_BULLET_LIST) {
+ strbuf_puts(html, "\n");
+ }
+ else if (list->start == 1) {
+ strbuf_puts(html, "\n");
+ }
+ else {
+ strbuf_printf(html, "\n",
+ list->start);
+ }
+
+ // Store the current value of 'tight' by swapping.
+ tmp = list->tight;
+ list->tight = tight;
+ tight = tmp;
+ break;
+ }
+
+ case NODE_ATX_HEADER:
+ case NODE_SETEXT_HEADER:
+ cr(html);
+ start_header[2] = '0' + cur->as.header.level;
+ strbuf_puts(html, start_header);
+ break;
+
+ case NODE_INDENTED_CODE:
+ case NODE_FENCED_CODE: {
+ strbuf *info = &cur->as.code.info;
+ cr(html);
+
+ if (cur->type != NODE_FENCED_CODE
+ || strbuf_len(info) == 0) {
+ strbuf_puts(html, "");
+ }
+ else {
+ int first_tag = strbuf_strchr(info, ' ', 0);
+ if (first_tag < 0)
+ first_tag = strbuf_len(info);
+
+ strbuf_puts(html,
+ "ptr, first_tag);
+ strbuf_puts(html, "\">");
+ }
+
+ escape_html(html, cur->string_content.ptr, cur->string_content.size);
+ break;
+ }
+
+ case NODE_HTML:
+ strbuf_put(html, cur->string_content.ptr, cur->string_content.size);
+ break;
+
+ case NODE_HRULE:
+ strbuf_puts(html, "
\n");
+ break;
+
+ case NODE_REFERENCE_DEF:
+ break;
+
case NODE_STRING:
- escape_html(html, ils->as.literal.data, ils->as.literal.len);
+ escape_html(html, cur->as.literal.data, cur->as.literal.len);
break;
case NODE_LINEBREAK:
@@ -153,217 +205,154 @@ static void inlines_to_html(strbuf *html, cmark_node* ils)
case NODE_INLINE_CODE:
strbuf_puts(html, "");
- escape_html(html, ils->as.literal.data, ils->as.literal.len);
- strbuf_puts(html, "
");
+ escape_html(html, cur->as.literal.data, cur->as.literal.len);
break;
case NODE_INLINE_HTML:
strbuf_put(html,
- ils->as.literal.data,
- ils->as.literal.len);
+ cur->as.literal.data,
+ cur->as.literal.len);
break;
case NODE_LINK:
strbuf_puts(html, "as.link.url)
- escape_href(html, ils->as.link.url, -1);
+ if (cur->as.link.url)
+ escape_href(html, cur->as.link.url, -1);
- if (ils->as.link.title) {
+ if (cur->as.link.title) {
strbuf_puts(html, "\" title=\"");
- escape_html(html, ils->as.link.title, -1);
+ escape_html(html, cur->as.link.title, -1);
}
strbuf_puts(html, "\">");
- visit_children = true;
- rstack = push_render_stack(rstack, ils->next, "");
break;
case NODE_IMAGE:
strbuf_puts(html, "as.link.url)
- escape_href(html, ils->as.link.url, -1);
+ if (cur->as.link.url)
+ escape_href(html, cur->as.link.url, -1);
strbuf_puts(html, "\" alt=\"");
- inlines_to_plain_html(html, ils->first_child);
+ inlines_to_plain_html(html, cur);
- if (ils->as.link.title) {
+ if (cur->as.link.title) {
strbuf_puts(html, "\" title=\"");
- escape_html(html, ils->as.link.title, -1);
+ escape_html(html, cur->as.link.title, -1);
}
strbuf_puts(html, "\" />");
+ visit_children = false;
break;
case NODE_STRONG:
strbuf_puts(html, "");
- visit_children = true;
- rstack = push_render_stack(rstack, ils->next, "");
break;
case NODE_EMPH:
strbuf_puts(html, "");
- visit_children = true;
- rstack = push_render_stack(rstack, ils->next, "");
break;
+
default:
- break;
+ assert(false);
}
- if (visit_children) {
- ils = ils->first_child;
- } else {
- ils = ils->next;
+
+ if (visit_children && cur->first_child) {
+ cur = cur->first_child;
+ continue;
+ }
+
+ next_sibling:
+ tight = finish_node(html, cur, tight);
+ if (cur == node) {
+ break;
}
- while (ils == NULL && rstack != NULL) {
- strbuf_puts(html, rstack->literal);
- ils = rstack->next_sibling;
- rstack = pop_render_stack(rstack);
+ if (cur->next) {
+ cur = cur->next;
+ continue;
}
+ cur = cur->parent;
+ goto next_sibling;
}
-
- free_render_stack(rstack);
}
-// Convert a cmark_node list to HTML. Returns 0 on success, and sets result.
-static void blocks_to_html(strbuf *html, cmark_node *b)
+// Returns the restored value of 'tight'.
+static bool
+finish_node(strbuf *html, cmark_node *node, bool tight)
{
- cmark_list *data;
- render_stack* rstack = NULL;
- bool visit_children = false;
- bool tight = false;
-
- while(b != NULL) {
- visit_children = false;
- switch(b->type) {
- case NODE_DOCUMENT:
- rstack = push_render_stack(rstack, b->next, "");
- rstack->tight = false;
- rstack->trim = false;
- visit_children = true;
- break;
-
- case NODE_PARAGRAPH:
- if (tight) {
- inlines_to_html(html, b->first_child);
- } else {
- cr(html);
- strbuf_puts(html, "");
- inlines_to_html(html, b->first_child);
- strbuf_puts(html, "
\n");
- }
- break;
+ char end_header[] = "
\n";
- case NODE_BQUOTE:
- cr(html);
- strbuf_puts(html, "\n");
- rstack = push_render_stack(rstack, b->next, "
\n");
- rstack->tight = tight;
- rstack->trim = false;
- tight = false;
- visit_children = true;
- break;
-
- case NODE_LIST_ITEM:
- cr(html);
- strbuf_puts(html, "");
- rstack = push_render_stack(rstack, b->next, "\n");
- rstack->tight = tight;
- rstack->trim = true;
- visit_children = true;
- break;
-
- case NODE_LIST:
- // make sure a list starts at the beginning of the line:
- cr(html);
- data = &(b->as.list);
-
- if (data->start > 1) {
- strbuf_printf(html, "<%s start=\"%d\">\n",
- data->list_type == CMARK_BULLET_LIST ? "ul" : "ol",
- data->start);
- } else {
- strbuf_puts(html, data->list_type == CMARK_BULLET_LIST ? "\n" : "\n");
- }
-
- rstack = push_render_stack(rstack, b->next,
- data->list_type == CMARK_BULLET_LIST ?
- "\n
\n" : "\n\n");
- rstack->tight = tight;
- rstack->trim = false;
- tight = data->tight;
- visit_children = true;
- break;
-
- case NODE_ATX_HEADER:
- case NODE_SETEXT_HEADER:
- cr(html);
- strbuf_printf(html, "", b->as.header.level);
- inlines_to_html(html, b->first_child);
- strbuf_printf(html, "\n", b->as.header.level);
- break;
-
- case NODE_INDENTED_CODE:
- case NODE_FENCED_CODE:
- cr(html);
-
- strbuf_puts(html, "type) {
+ case NODE_PARAGRAPH:
+ if (!tight) {
+ strbuf_puts(html, "
\n");
+ }
+ break;
+
+ case NODE_BQUOTE: {
+ cmark_list *list = &node->as.list;
+ strbuf_puts(html, "\n");
+ // Restore old 'tight' value.
+ tight = list->tight;
+ list->tight = false;
+ break;
+ }
- if (b->type == NODE_FENCED_CODE) {
- strbuf *info = &b->as.code.info;
+ case NODE_LIST_ITEM:
+ strbuf_puts(html, "\n");
+ break;
+
+ case NODE_LIST: {
+ cmark_list *list = &node->as.list;
+ bool tmp;
+ strbuf_puts(html,
+ list->list_type == CMARK_BULLET_LIST ?
+ "\n" : "\n");
+ // Restore old 'tight' value.
+ tmp = tight;
+ tight = list->tight;
+ list->tight = tmp;
+ break;
+ }
- if (strbuf_len(info) > 0) {
- int first_tag = strbuf_strchr(info, ' ', 0);
- if (first_tag < 0)
- first_tag = strbuf_len(info);
+ case NODE_ATX_HEADER:
+ case NODE_SETEXT_HEADER:
+ end_header[3] = '0' + node->as.header.level;
+ strbuf_puts(html, end_header);
+ break;
- strbuf_puts(html, " class=\"language-");
- escape_html(html, info->ptr, first_tag);
- strbuf_putc(html, '"');
- }
- }
+ case NODE_INDENTED_CODE:
+ case NODE_FENCED_CODE:
+ strbuf_puts(html, "\n");
+ break;
- strbuf_putc(html, '>');
- escape_html(html, b->string_content.ptr, b->string_content.size);
- strbuf_puts(html, "\n");
- break;
+ case NODE_INLINE_CODE:
+ strbuf_puts(html, "");
+ break;
- case NODE_HTML:
- strbuf_put(html, b->string_content.ptr, b->string_content.size);
- break;
+ case NODE_LINK:
+ strbuf_puts(html, "");
+ break;
- case NODE_HRULE:
- strbuf_puts(html, "
\n");
- break;
+ case NODE_STRONG:
+ strbuf_puts(html, "");
+ break;
- case NODE_REFERENCE_DEF:
- break;
+ case NODE_EMPH:
+ strbuf_puts(html, "");
+ break;
- default:
- assert(false);
- }
- if (visit_children) {
- b = b->first_child;
- } else {
- b = b->next;
- }
- while (b == NULL && rstack != NULL) {
- strbuf_puts(html, rstack->literal);
- if (rstack->trim) {
- strbuf_rtrim(html);
- }
- tight = rstack->tight;
- b = rstack->next_sibling;
- rstack = pop_render_stack(rstack);
- }
+ default:
+ break;
}
- free_render_stack(rstack);
+ return tight;
}
unsigned char *cmark_render_html(cmark_node *root)
{
unsigned char *result;
strbuf html = GH_BUF_INIT;
- blocks_to_html(&html, root);
+ node_to_html(&html, root);
result = strbuf_detach(&html);
strbuf_free(&html);
return result;
--
cgit v1.2.3
From c100b483db2a35d004288f128c0c27d9976fc9c9 Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer
Date: Sat, 22 Nov 2014 17:16:10 +0100
Subject: Make render_html return a char*
---
src/cmark.c | 4 ++--
src/cmark.h | 4 ++--
src/html/html.c | 6 +++---
src/main.c | 2 +-
4 files changed, 8 insertions(+), 8 deletions(-)
(limited to 'src')
diff --git a/src/cmark.c b/src/cmark.c
index b20b84b..07b7c4c 100644
--- a/src/cmark.c
+++ b/src/cmark.c
@@ -7,10 +7,10 @@
#include "cmark.h"
#include "buffer.h"
-unsigned char *cmark_markdown_to_html(unsigned char *text, int len)
+char *cmark_markdown_to_html(unsigned char *text, int len)
{
cmark_node *blocks;
- unsigned char *result;
+ char *result;
blocks = cmark_parse_document(text, len);
diff --git a/src/cmark.h b/src/cmark.h
index a74fe93..206b667 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -190,10 +190,10 @@ CMARK_EXPORT
void cmark_debug_print(cmark_node *root);
CMARK_EXPORT
-unsigned char *cmark_render_html(cmark_node *root);
+char *cmark_render_html(cmark_node *root);
CMARK_EXPORT
-unsigned char *cmark_markdown_to_html(unsigned char *text, int len);
+char *cmark_markdown_to_html(unsigned char *text, int len);
#ifndef CMARK_NO_SHORT_NAMES
#define NODE_DOCUMENT CMARK_NODE_DOCUMENT
diff --git a/src/html/html.c b/src/html/html.c
index 96fce66..4fa79b1 100644
--- a/src/html/html.c
+++ b/src/html/html.c
@@ -348,12 +348,12 @@ finish_node(strbuf *html, cmark_node *node, bool tight)
return tight;
}
-unsigned char *cmark_render_html(cmark_node *root)
+char *cmark_render_html(cmark_node *root)
{
- unsigned char *result;
+ char *result;
strbuf html = GH_BUF_INIT;
node_to_html(&html, root);
- result = strbuf_detach(&html);
+ result = (char *)strbuf_detach(&html);
strbuf_free(&html);
return result;
}
diff --git a/src/main.c b/src/main.c
index 1cfddda..61d98dc 100644
--- a/src/main.c
+++ b/src/main.c
@@ -17,7 +17,7 @@ void print_usage()
static void print_document(cmark_node *document, bool ast)
{
- unsigned char *result;
+ char *result;
if (ast) {
cmark_debug_print(document);
} else {
--
cgit v1.2.3
From b2dac901288a3431fdadd9bbefb7875596a13e4d Mon Sep 17 00:00:00 2001
From: Nick Wellnhofer
Date: Sat, 22 Nov 2014 17:23:37 +0100
Subject: Make parser accept a char*
---
src/blocks.c | 16 ++++++++--------
src/cmark.c | 2 +-
src/cmark.h | 6 +++---
src/main.c | 2 +-
4 files changed, 13 insertions(+), 13 deletions(-)
(limited to 'src')
diff --git a/src/blocks.c b/src/blocks.c
index ab9f667..a30560f 100644
--- a/src/blocks.c
+++ b/src/blocks.c
@@ -416,13 +416,13 @@ static cmark_node *finalize_document(cmark_doc_parser *parser)
extern cmark_node *cmark_parse_file(FILE *f)
{
- unsigned char buffer[4096];
+ char buffer[4096];
cmark_doc_parser *parser = cmark_new_doc_parser();
size_t offset;
cmark_node *document;
- while (fgets((char *)buffer, sizeof(buffer), f)) {
- offset = strlen((char *)buffer);
+ while (fgets(buffer, sizeof(buffer), f)) {
+ offset = strlen(buffer);
cmark_process_line(parser, buffer, offset);
}
@@ -431,16 +431,16 @@ extern cmark_node *cmark_parse_file(FILE *f)
return document;
}
-extern cmark_node *cmark_parse_document(const unsigned char *buffer, size_t len)
+extern cmark_node *cmark_parse_document(const char *buffer, size_t len)
{
int linenum = 1;
- const unsigned char *end = buffer + len;
+ const char *end = buffer + len;
size_t offset;
cmark_doc_parser *parser = cmark_new_doc_parser();
cmark_node *document;
while (buffer < end) {
- const unsigned char *eol = (unsigned char *)memchr(buffer, '\n', end - buffer);
+ const char *eol = memchr(buffer, '\n', end - buffer);
offset = eol ? (eol - buffer) + 1 : eol - buffer;
cmark_process_line(parser, buffer, offset);
buffer += offset;
@@ -470,7 +470,7 @@ static void chop_trailing_hashtags(chunk *ch)
}
}
-void cmark_process_line(cmark_doc_parser *parser, const unsigned char *buffer,
+void cmark_process_line(cmark_doc_parser *parser, const char *buffer,
size_t bytes)
{
cmark_node* last_matched_container;
@@ -487,7 +487,7 @@ void cmark_process_line(cmark_doc_parser *parser, const unsigned char *buffer,
int indent;
chunk input;
- utf8proc_detab(parser->curline, buffer, bytes);
+ utf8proc_detab(parser->curline, (unsigned char *)buffer, bytes);
// Add a newline to the end if not present:
// TODO this breaks abstraction:
diff --git a/src/cmark.c b/src/cmark.c
index 07b7c4c..273a37b 100644
--- a/src/cmark.c
+++ b/src/cmark.c
@@ -7,7 +7,7 @@
#include "cmark.h"
#include "buffer.h"
-char *cmark_markdown_to_html(unsigned char *text, int len)
+char *cmark_markdown_to_html(const char *text, int len)
{
cmark_node *blocks;
char *result;
diff --git a/src/cmark.h b/src/cmark.h
index 206b667..6131024 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -176,10 +176,10 @@ CMARK_EXPORT
cmark_node *cmark_finish(cmark_doc_parser *parser);
CMARK_EXPORT
-void cmark_process_line(cmark_doc_parser *parser, const unsigned char *buffer, size_t bytes);
+void cmark_process_line(cmark_doc_parser *parser, const char *buffer, size_t bytes);
CMARK_EXPORT
-cmark_node *cmark_parse_document(const unsigned char *buffer, size_t len);
+cmark_node *cmark_parse_document(const char *buffer, size_t len);
CMARK_EXPORT
cmark_node *cmark_parse_file(FILE *f);
@@ -193,7 +193,7 @@ CMARK_EXPORT
char *cmark_render_html(cmark_node *root);
CMARK_EXPORT
-char *cmark_markdown_to_html(unsigned char *text, int len);
+char *cmark_markdown_to_html(const char *text, int len);
#ifndef CMARK_NO_SHORT_NAMES
#define NODE_DOCUMENT CMARK_NODE_DOCUMENT
diff --git a/src/main.c b/src/main.c
index 61d98dc..96e53ce 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,7 +33,7 @@ int main(int argc, char *argv[])
int i, numfps = 0;
bool ast = false;
int *files;
- unsigned char buffer[4096];
+ char buffer[4096];
cmark_doc_parser *parser;
size_t offset;
cmark_node *document;
--
cgit v1.2.3