cmark

My personal build of CMark ✏️

Commit
6ecd359a195d3dce3c093cc955936e4ed954b48d
Parent
d64b1d286960ddf59df8dda9ab749b27a72ed6d1
Author
John MacFarlane <jgm@berkeley.edu>
Date

cmark_render: ensure final newline.

This allows us to remove direct manipulation of buffer from the latex and commonmark renderers.

Diffstat

3 files changed, 5 insertions, 6 deletions

Status File Name N° Changes Insertions Deletions
Modified src/commonmark.c 3 0 3
Modified src/latex.c 3 0 3
Modified src/render.c 5 5 0
diff --git a/src/commonmark.c b/src/commonmark.c
@@ -195,9 +195,6 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
 
 	switch (node->type) {
 	case CMARK_NODE_DOCUMENT:
-		if (!entering) {
-			cmark_strbuf_putc(renderer->buffer, '\n');
-		}
 		break;
 
 	case CMARK_NODE_BLOCK_QUOTE:
diff --git a/src/latex.c b/src/latex.c
@@ -285,9 +285,6 @@ S_render_node(cmark_node *node, cmark_event_type ev_type,
 
 	switch (node->type) {
 	case CMARK_NODE_DOCUMENT:
-		if (!entering) {
-			cmark_strbuf_putc(renderer->buffer, '\n');
-		}
 		break;
 
 	case CMARK_NODE_BLOCK_QUOTE:
diff --git a/src/render.c b/src/render.c
@@ -154,6 +154,11 @@ cmark_render(cmark_node *root,
 		}
 	}
 
+	// ensure final newline
+	if (renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') {
+		cmark_strbuf_putc(renderer.buffer, '\n');
+	}
+
 	result = (char *)cmark_strbuf_detach(renderer.buffer);
 
 	cmark_iter_free(iter);