cmark

My personal build of CMark ✏️

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

Improved cmark_markdown_to_html.

Added length parameter so we can avoid strlen. Properly free buffer.

Diffstat

2 files changed, 8 insertions, 4 deletions

Status File Name N° Changes Insertions Deletions
Modified src/cmark.c 10 7 3
Modified src/cmark.h 2 1 1
diff --git a/src/cmark.c b/src/cmark.c
@@ -5,15 +5,19 @@
 #include "cmark.h"
 #include "buffer.h"
 
-extern unsigned char *cmark_markdown_to_html(unsigned char *text)
+extern unsigned char *cmark_markdown_to_html(unsigned char *text, int len)
 {
 	node_block *blocks;
 	strbuf htmlbuf = GH_BUF_INIT;
+	unsigned char *result;
 
-	blocks = cmark_parse_document(text, sizeof(text));
+	blocks = cmark_parse_document(text, len);
 
 	cmark_render_html(&htmlbuf, blocks);
 	cmark_free_nodes(blocks);
 
-	return strbuf_detach(&htmlbuf);
+	result = strbuf_detach(&htmlbuf);
+	strbuf_free(&htmlbuf);
+
+	return result;
 }
diff --git a/src/cmark.h b/src/cmark.h
@@ -118,7 +118,7 @@ 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);
+unsigned char *cmark_markdown_to_html(unsigned char *text, int len);
 
 #ifdef __cplusplus
 }