Skip to content
Open
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
7 changes: 7 additions & 0 deletions api_test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,13 @@ static void test_content(test_batch_runner *runner, cmark_node_type type,
static void parser(test_batch_runner *runner) {
test_md_to_html(runner, "No newline", "<p>No newline</p>\n",
"document without trailing newline");

// Only spaces are removed before a soft line break; a trailing tab is
// kept, matching the spec (which strips only end-of-line spaces).
test_md_to_html(runner, "foo\t\nbar\n", "<p>foo\t\nbar</p>\n",
"trailing tab kept before soft line break");
test_md_to_html(runner, "foo \nbar\n", "<p>foo\nbar</p>\n",
"trailing space removed before soft line break");
}

static void render_html(test_batch_runner *runner) {
Expand Down
7 changes: 5 additions & 2 deletions src/inlines.c
Original file line number Diff line number Diff line change
Expand Up @@ -1399,9 +1399,12 @@ static int parse_inline(subject *subj, cmark_node *parent, int options) {
startpos = subj->pos;
subj->pos = endpos;

// if we're at a newline, strip trailing spaces.
// if we're at a newline, strip trailing spaces. Only spaces are
// removed before a line ending; trailing tabs are preserved, as the
// spec strips only spaces at the end of a line (a final tab is kept).
if (S_is_line_end_char(peek_char(subj))) {
cmark_chunk_rtrim(&contents);
while (contents.len > 0 && contents.data[contents.len - 1] == ' ')
contents.len--;
}

new_inl = make_str(subj, startpos, endpos - 1, contents);
Expand Down
Loading