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* --- api_test/main.c | 16 +++++++++------- src/cmark.c | 4 ++-- src/cmark.h | 4 ++-- src/html/html.c | 6 +++--- src/main.c | 2 +- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/api_test/main.c b/api_test/main.c index da9e241..a946c1a 100644 --- a/api_test/main.c +++ b/api_test/main.c @@ -2,6 +2,7 @@ #include #include +#define CMARK_NO_SHORT_NAMES #include "cmark.h" #include "node.h" @@ -186,7 +187,7 @@ accessors(test_batch_runner *runner) OK(runner, cmark_node_set_string_content(string, "LINK"), "set_string_content string"); - char *rendered_html = (char *)cmark_render_html(doc); + char *rendered_html = cmark_render_html(doc); static const char expected_html[] = "

Header

\n" "
    \n" @@ -306,7 +307,7 @@ create_tree(test_batch_runner *runner) OK(runner, cmark_node_append_child(emph, str2), "append3"); INT_EQ(runner, cmark_node_check(doc, NULL), 0, "append3 consistent"); - html = (char *)cmark_render_html(doc); + html = cmark_render_html(doc); STR_EQ(runner, html, "

    Hello, world!

    \n", "render_html"); free(html); @@ -337,7 +338,7 @@ create_tree(test_batch_runner *runner) cmark_node_unlink(emph); - html = (char *)cmark_render_html(doc); + html = cmark_render_html(doc); STR_EQ(runner, html, "

    Hello, !

    \n", "render_html after shuffling"); free(html); @@ -439,7 +440,8 @@ test_content(test_batch_runner *runner, cmark_node_type type, cmark_node_destroy(node); } -void render_html(test_batch_runner *runner) +static void +render_html(test_batch_runner *runner) { char *html; @@ -450,18 +452,18 @@ void render_html(test_batch_runner *runner) cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1); cmark_node *paragraph = cmark_node_first_child(doc); - html = (char *)cmark_render_html(paragraph); + html = cmark_render_html(paragraph); STR_EQ(runner, html, "

    foo bar

    \n", "render single paragraph"); free(html); cmark_node *string = cmark_node_first_child(paragraph); - html = (char *)cmark_render_html(string); + html = cmark_render_html(string); STR_EQ(runner, html, "foo ", "render single inline"); free(html); cmark_node *emph = cmark_node_next(string); - html = (char *)cmark_render_html(emph); + html = cmark_render_html(emph); STR_EQ(runner, html, "bar", "render inline with children"); free(html); 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