cmark

My personal build of CMark ✏️

Commit
cb744bd09103321b18ee979edac2cb26a414f7be
Parent
f8d804300a134993a667ecf66063ee15accc6712
Author
John MacFarlane <fiddlosopher@gmail.com>
Date

Added cmark_markdown_to_html with a simple interface.

See #70.

Diffstat

4 files changed, 23 insertions, 1 deletion

Status File Name N° Changes Insertions Deletions
Modified src/CMakeLists.txt 1 1 0
Added src/cmark.c 19 19 0
Modified src/cmark.h 2 2 0
Modified src/html/html.c 2 1 1
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);
 }