cmark

My personal build of CMark ✏️

Commit
7bc7581b22fbb2f77529a5ac9bca57ed1916bd32
Parent
8ee6f28d2fe0d990da8bdd88579dcd8cc488d01b
Author
John MacFarlane <fiddlosopher@gmail.com>
Date

Replaced cmark_debug_print with cmark_render_ast.

This returns a string.

Diffstat

3 files changed, 9 insertions, 6 deletions

Status File Name N° Changes Insertions Deletions
Modified src/cmark.h 2 1 1
Modified src/main.c 6 3 3
Modified src/print.c 7 5 2
diff --git a/src/cmark.h b/src/cmark.h
@@ -185,7 +185,7 @@ cmark_node *cmark_parse_file(FILE *f);
 // Renderer
 
 CMARK_EXPORT
-void cmark_debug_print(cmark_node *root);
+char *cmark_render_ast(cmark_node *root);
 
 CMARK_EXPORT
 char *cmark_render_html(cmark_node *root);
diff --git a/src/main.c b/src/main.c
@@ -19,13 +19,13 @@ static void print_document(cmark_node *document, bool ast)
 {
 	char *result;
 	if (ast) {
-		cmark_debug_print(document);
+		result = cmark_render_ast(document);
 	} else {
 
 		result = cmark_render_html(document);
-		printf("%s", result);
-		free(result);
 	}
+	printf("%s", result);
+	free(result);
 }
 
 int main(int argc, char *argv[])
diff --git a/src/print.c b/src/print.c
@@ -158,9 +158,12 @@ static void render_nodes(strbuf* buffer, cmark_node* node, int indent)
 	}
 }
 
-void cmark_debug_print(cmark_node *root)
+char *cmark_render_ast(cmark_node *root)
 {
+	char* result;
 	strbuf buffer = GH_BUF_INIT;
 	render_nodes(&buffer, root, -2);
-	printf("%s", buffer.ptr);
+	result = (char *)strbuf_detach(&buffer);
+	strbuf_free(&buffer);
+	return result;
 }