Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't append a newline character when rendering inline nodes. #559

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ static void render_commonmark(test_batch_runner *runner) {
cmark_node *text = cmark_node_new(CMARK_NODE_TEXT);
cmark_node_set_literal(text, "Hi");
commonmark = cmark_render_commonmark(text, CMARK_OPT_DEFAULT, 0);
STR_EQ(runner, commonmark, "Hi\n", "render single inline node");
STR_EQ(runner, commonmark, "Hi", "render single inline node");
free(commonmark);

cmark_node_free(text);
Expand Down
8 changes: 5 additions & 3 deletions src/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ char *cmark_render(cmark_node *root, int options, int width,
}
}

// ensure final newline
if (renderer.buffer->size == 0 || renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') {
cmark_strbuf_putc(renderer.buffer, '\n');
// If the root node is a block type (i.e. not inline), ensure there's a final newline:
if (cmark_node_is_block(root)) {
if (renderer.buffer->size == 0 || renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') {
cmark_strbuf_putc(renderer.buffer, '\n');
}
}

result = (char *)cmark_strbuf_detach(renderer.buffer);
Expand Down