Skip to content

Commit

Permalink
Check for hard breaks more carefully to avoid false positives...
Browse files Browse the repository at this point in the history
... caused by trailing tab characters.

Fixes #250.
  • Loading branch information
mity committed Feb 25, 2024
1 parent 64f3680 commit 481fbfb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/md4c.c
Original file line number Diff line number Diff line change
Expand Up @@ -4470,12 +4470,14 @@ md_process_inlines(MD_CTX* ctx, const MD_LINE* lines, MD_SIZE n_lines)
MD_TEXTTYPE break_type = MD_TEXT_SOFTBR;

if(text_type == MD_TEXT_NORMAL) {
if(ctx->parser.flags & MD_FLAG_HARD_SOFT_BREAKS)
break_type = MD_TEXT_BR;
else if(enforce_hardbreak)
break_type = MD_TEXT_BR;
else if((CH(line->end) == _T(' ') && CH(line->end+1) == _T(' ')))
if(enforce_hardbreak || (ctx->parser.flags & MD_FLAG_HARD_SOFT_BREAKS)) {
break_type = MD_TEXT_BR;
} else {
while(off < ctx->size && ISBLANK(off))
off++;
if(off >= line->end + 2 && CH(off-2) == _T(' ') && CH(off-1) == _T(' ') && ISNEWLINE(off))
break_type = MD_TEXT_BR;
}
}

MD_TEXT(break_type, _T("\n"), 1);
Expand Down
24 changes: 24 additions & 0 deletions test/regressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -761,3 +761,27 @@ baz*→
<h1>Foo <em>bar
baz</em></h1>
````````````````````````````````


## [Issue 250](https://github.com/mity/md4c/issues/250)

Handling trailing tabulator character versus hard break.

Space + space + tab + newline is not hard break:
```````````````````````````````` example [no-normalize]
foo →
bar
.
<p>foo
bar</p>
````````````````````````````````

Tab + space + space + newline is hard break:
```````````````````````````````` example [no-normalize]
foo→
bar
.
<p>foo<br>
bar</p>
````````````````````````````````

0 comments on commit 481fbfb

Please sign in to comment.