cmark

Unnamed repository; edit this file 'description' to name the repository.

commit cb744bd09103321b18ee979edac2cb26a414f7be
parent f8d804300a134993a667ecf66063ee15accc6712
Author: John MacFarlane <fiddlosopher@gmail.com>
Date:   Tue, 11 Nov 2014 12:00:42 -0800

Added cmark_markdown_to_html with a simple interface.

See #70.

Diffstat:
Msrc/CMakeLists.txt | 1+
Asrc/cmark.c | 19+++++++++++++++++++
Msrc/cmark.h | 2++
Msrc/html/html.c | 2+-
4 files changed, 23 insertions(+), 1 deletion(-)
diff --git 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
@@ -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
@@ -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
@@ -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);
 }