summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2014-11-11 12:00:42 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2014-11-11 12:01:00 -0800
commitcb744bd09103321b18ee979edac2cb26a414f7be (patch)
tree6a6837df1271598bf8bb056b03f1c41aa8195ffb
parentf8d804300a134993a667ecf66063ee15accc6712 (diff)
Added cmark_markdown_to_html with a simple interface.
See #70.
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/cmark.c19
-rw-r--r--src/cmark.h2
-rw-r--r--src/html/html.c2
4 files changed, 23 insertions, 1 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c0792cd..45b0fec 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -13,6 +13,7 @@ set(HEADERS
html/houdini.h
)
set(LIBRARY_SOURCES
+ cmark.c
blocks.c
inlines.c
print.c
diff --git a/src/cmark.c b/src/cmark.c
new file mode 100644
index 0000000..064c080
--- /dev/null
+++ b/src/cmark.c
@@ -0,0 +1,19 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+
+#include "cmark.h"
+#include "buffer.h"
+
+extern unsigned char *cmark_markdown_to_html(unsigned char *text)
+{
+ node_block *blocks;
+ strbuf htmlbuf = GH_BUF_INIT;
+
+ blocks = cmark_parse_document(text, sizeof(text));
+
+ cmark_render_html(&htmlbuf, blocks);
+ cmark_free_nodes(blocks);
+
+ return strbuf_detach(&htmlbuf);
+}
diff --git a/src/cmark.h b/src/cmark.h
index 1fb8668..6347901 100644
--- a/src/cmark.h
+++ b/src/cmark.h
@@ -118,6 +118,8 @@ void cmark_free_nodes(node_block *e);
void cmark_debug_print(node_block *root);
void cmark_render_html(strbuf *html, node_block *root);
+unsigned char *cmark_markdown_to_html(unsigned char *text);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/html/html.c b/src/html/html.c
index ea83992..6b5d614 100644
--- a/src/html/html.c
+++ b/src/html/html.c
@@ -372,7 +372,7 @@ static void blocks_to_html(strbuf *html, node_block *b)
free_render_stack(rstack);
}
-void cmark_render_html(strbuf *html, node_block *root)
+extern void cmark_render_html(strbuf *html, node_block *root)
{
blocks_to_html(html, root);
}