Check for hard breaks more carefully to avoid false positives... ... caused by trailing tab characters. Fixes #250.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/src/md4c.c b/src/md4c.c
index 3679526..e3f5cf9 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -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);
diff --git a/test/regressions.txt b/test/regressions.txt
index 836b970..70c2d16 100644
--- a/test/regressions.txt
+++ b/test/regressions.txt
@@ -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>
+````````````````````````````````
+