Commit 481fbfbdf72daab2912380d62bb5f2187d438408

Martin Mitáš 2024-02-25T20:51:06

Check for hard breaks more carefully to avoid false positives... ... caused by trailing tab characters. Fixes #250.

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>
+````````````````````````````````
+