cmark

My personal build of CMark ✏️

Commit
5a26ca5cf9481289ad77d6049b55c48feea7cc38
Parent
b7f6e3f775705029df262aa313a0cd17ee3073cb
Author
John MacFarlane <fiddlosopher@gmail.com>
Date

cmark_render_html now just returns a regular C string.

This way, we don't have to expose buffer.h; it is just used internally.

Diffstat

5 files changed, 12 insertions, 16 deletions

Status File Name N° Changes Insertions Deletions
Modified src/CMakeLists.txt 2 1 1
Modified src/cmark.c 6 1 5
Modified src/cmark.h 3 1 2
Modified src/html/html.c 10 8 2
Modified src/main.c 7 1 6
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
@@ -89,7 +89,7 @@ install(TARGETS ${PROGRAM} ${LIBRARY}
   LIBRARY DESTINATION lib
   )
 
-install(FILES cmark.h buffer.h chunk.h references.h ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h
+install(FILES cmark.h chunk.h ${CMAKE_CURRENT_BINARY_DIR}/cmark_export.h
   DESTINATION include/${PROJECT_NAME}
   )
 
diff --git a/src/cmark.c b/src/cmark.c
@@ -11,17 +11,13 @@
 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, len);
 
-	cmark_render_html(&htmlbuf, blocks);
+	result = cmark_render_html(blocks);
 	cmark_free_blocks(blocks);
 
-	result = strbuf_detach(&htmlbuf);
-	strbuf_free(&htmlbuf);
-
 	return result;
 }
 
diff --git a/src/cmark.h b/src/cmark.h
@@ -3,7 +3,6 @@
 
 #include <stdbool.h>
 #include <stdio.h>
-#include "buffer.h"
 #include "chunk.h"
 
 #ifdef __cplusplus
@@ -43,7 +42,7 @@ CMARK_EXPORT
 void cmark_debug_print(cmark_node_block *root);
 
 CMARK_EXPORT
-void cmark_render_html(cmark_strbuf *html, cmark_node_block *root);
+unsigned char *cmark_render_html(cmark_node_block *root);
 
 CMARK_EXPORT
 unsigned char *cmark_markdown_to_html(unsigned char *text, int len);
diff --git a/src/html/html.c b/src/html/html.c
@@ -5,6 +5,7 @@
 #include <assert.h>
 
 #include "cmark.h"
+#include "buffer.h"
 #include "ast.h"
 #include "debug.h"
 #include "html/houdini.h"
@@ -373,7 +374,12 @@ static void blocks_to_html(strbuf *html, node_block *b)
 	free_render_stack(rstack);
 }
 
-extern void cmark_render_html(strbuf *html, node_block *root)
+unsigned char *cmark_render_html(node_block *root)
 {
-	blocks_to_html(html, root);
+	unsigned char *result;
+	strbuf html = GH_BUF_INIT;
+	blocks_to_html(&html, root);
+	result = strbuf_detach(&html);
+	strbuf_free(&html);
+	return result;
 }
diff --git a/src/main.c b/src/main.c
@@ -3,7 +3,6 @@
 #include <string.h>
 #include <errno.h>
 #include "cmark.h"
-#include "buffer.h"
 #include "debug.h"
 #include "bench.h"
 
@@ -17,14 +16,10 @@ void print_usage()
 
 static void print_document(node_block *document, bool ast)
 {
-	strbuf html = GH_BUF_INIT;
-
 	if (ast) {
 		cmark_debug_print(document);
 	} else {
-		cmark_render_html(&html, document);
-		printf("%s", html.ptr);
-		strbuf_free(&html);
+		printf("%s", cmark_render_html(document));
 	}
 }