Skip to content

Commit 64f3680

Browse files
committedFeb 25, 2024··
Fix handling tab when removing trailing whitespace.
Espacially in connection with ATX headers.
1 parent 3848bfb commit 64f3680

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ Fixes:
1919
same logic as other emphasis spans in respect to punctuation character and
2020
word boundaries.
2121

22+
- [#248](https://github.com/mity/md4c/issues/248):
23+
Fix handling tab when removing trailing whitespace, especially in connection
24+
with ATX headers.
25+
2226

2327
## Version 0.5.2
2428

‎src/md4c.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -5250,10 +5250,10 @@ md_is_atxheader_line(MD_CTX* ctx, OFF beg, OFF* p_beg, OFF* p_end, unsigned* p_l
52505250
*p_level = n;
52515251

52525252
if(!(ctx->parser.flags & MD_FLAG_PERMISSIVEATXHEADERS) && off < ctx->size &&
5253-
CH(off) != _T(' ') && CH(off) != _T('\t') && !ISNEWLINE(off))
5253+
!ISBLANK(off) && !ISNEWLINE(off))
52545254
return FALSE;
52555255

5256-
while(off < ctx->size && CH(off) == _T(' '))
5256+
while(off < ctx->size && ISBLANK(off))
52575257
off++;
52585258
*p_beg = off;
52595259
*p_end = off;
@@ -6248,17 +6248,17 @@ md_analyze_line(MD_CTX* ctx, OFF beg, OFF* p_end,
62486248
/* But for ATX header, we should exclude the optional trailing mark. */
62496249
if(line->type == MD_LINE_ATXHEADER) {
62506250
OFF tmp = line->end;
6251-
while(tmp > line->beg && CH(tmp-1) == _T(' '))
6251+
while(tmp > line->beg && ISBLANK(tmp-1))
62526252
tmp--;
62536253
while(tmp > line->beg && CH(tmp-1) == _T('#'))
62546254
tmp--;
6255-
if(tmp == line->beg || CH(tmp-1) == _T(' ') || (ctx->parser.flags & MD_FLAG_PERMISSIVEATXHEADERS))
6255+
if(tmp == line->beg || ISBLANK(tmp-1) || (ctx->parser.flags & MD_FLAG_PERMISSIVEATXHEADERS))
62566256
line->end = tmp;
62576257
}
62586258

62596259
/* Trim trailing spaces. */
62606260
if(line->type != MD_LINE_INDENTEDCODE && line->type != MD_LINE_FENCEDCODE && line->type != MD_LINE_HTML) {
6261-
while(line->end > line->beg && CH(line->end-1) == _T(' '))
6261+
while(line->end > line->beg && ISBLANK(line->end-1))
62626262
line->end--;
62636263
}
62646264

‎test/regressions.txt

+21
Original file line numberDiff line numberDiff line change
@@ -740,3 +740,24 @@ copy "~user1/file" to "~user2/file"
740740
.
741741
--fstrikethrough
742742
````````````````````````````````
743+
744+
745+
## [Issue 248](https://github.com/mity/md4c/issues/248)
746+
747+
(These are in spec.txt, but we need the [no-normalize] flag in order to
748+
catch the whitespace issues.)
749+
750+
```````````````````````````````` example [no-normalize]
751+
#→Foo
752+
.
753+
<h1>Foo</h1>
754+
````````````````````````````````
755+
756+
```````````````````````````````` example [no-normalize]
757+
Foo *bar
758+
baz*→
759+
====
760+
.
761+
<h1>Foo <em>bar
762+
baz</em></h1>
763+
````````````````````````````````

0 commit comments

Comments
 (0)
Please sign in to comment.