From 6ecd359a195d3dce3c093cc955936e4ed954b48d Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 12 Jul 2015 13:46:35 -0700 Subject: cmark_render: ensure final newline. This allows us to remove direct manipulation of buffer from the latex and commonmark renderers. --- src/commonmark.c | 3 --- src/latex.c | 3 --- src/render.c | 5 +++++ 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/commonmark.c b/src/commonmark.c index 44f8788..09644a0 100644 --- 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 index 058f212..684c855 100644 --- 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 index 16caadc..f60835f 100644 --- 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); -- cgit v1.2.3