Fix handling tab when removing trailing whitespace. Espacially in connection with ATX headers.
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e02071b..dbb6317 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,10 @@ Fixes:
same logic as other emphasis spans in respect to punctuation character and
word boundaries.
+ - [#248](https://github.com/mity/md4c/issues/248):
+ Fix handling tab when removing trailing whitespace, especially in connection
+ with ATX headers.
+
## Version 0.5.2
diff --git a/src/md4c.c b/src/md4c.c
index 054c559..3679526 100644
--- a/src/md4c.c
+++ b/src/md4c.c
@@ -5250,10 +5250,10 @@ md_is_atxheader_line(MD_CTX* ctx, OFF beg, OFF* p_beg, OFF* p_end, unsigned* p_l
*p_level = n;
if(!(ctx->parser.flags & MD_FLAG_PERMISSIVEATXHEADERS) && off < ctx->size &&
- CH(off) != _T(' ') && CH(off) != _T('\t') && !ISNEWLINE(off))
+ !ISBLANK(off) && !ISNEWLINE(off))
return FALSE;
- while(off < ctx->size && CH(off) == _T(' '))
+ while(off < ctx->size && ISBLANK(off))
off++;
*p_beg = off;
*p_end = off;
@@ -6248,17 +6248,17 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end,
/* But for ATX header, we should exclude the optional trailing mark. */
if(line->type == MD_LINE_ATXHEADER) {
OFF tmp = line->end;
- while(tmp > line->beg && CH(tmp-1) == _T(' '))
+ while(tmp > line->beg && ISBLANK(tmp-1))
tmp--;
while(tmp > line->beg && CH(tmp-1) == _T('#'))
tmp--;
- if(tmp == line->beg || CH(tmp-1) == _T(' ') || (ctx->parser.flags & MD_FLAG_PERMISSIVEATXHEADERS))
+ if(tmp == line->beg || ISBLANK(tmp-1) || (ctx->parser.flags & MD_FLAG_PERMISSIVEATXHEADERS))
line->end = tmp;
}
/* Trim trailing spaces. */
if(line->type != MD_LINE_INDENTEDCODE && line->type != MD_LINE_FENCEDCODE && line->type != MD_LINE_HTML) {
- while(line->end > line->beg && CH(line->end-1) == _T(' '))
+ while(line->end > line->beg && ISBLANK(line->end-1))
line->end--;
}
diff --git a/test/regressions.txt b/test/regressions.txt
index 7411206..836b970 100644
--- a/test/regressions.txt
+++ b/test/regressions.txt
@@ -740,3 +740,24 @@ copy "~user1/file" to "~user2/file"
.
--fstrikethrough
````````````````````````````````
+
+
+## [Issue 248](https://github.com/mity/md4c/issues/248)
+
+(These are in spec.txt, but we need the [no-normalize] flag in order to
+catch the whitespace issues.)
+
+```````````````````````````````` example [no-normalize]
+#→Foo
+.
+<h1>Foo</h1>
+````````````````````````````````
+
+```````````````````````````````` example [no-normalize]
+ Foo *bar
+baz*→
+====
+.
+<h1>Foo <em>bar
+baz</em></h1>
+````````````````````````````````