Skip to content

Commit

Permalink
Make striketrough spans follow same flanking rules...
Browse files Browse the repository at this point in the history
... as other emphasis spans.

Fixes #242.
  • Loading branch information
mity committed Feb 21, 2024
1 parent 057915e commit 3848bfb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Fixes:
Fix quadratic time and output size behavior caused by malicious misuse of
link reference definitions.

- [#242](https://github.com/mity/md4c/issues/242):
The strike-through extension (with flag `MD_FLAG_STRIKETHROUGH`) now follows
same logic as other emphasis spans in respect to punctuation character and
word boundaries.


## Version 0.5.2

Expand Down
30 changes: 3 additions & 27 deletions src/md4c.c
Original file line number Diff line number Diff line change
Expand Up @@ -3295,35 +3295,11 @@ md_collect_marks(MD_CTX* ctx, const MD_LINE* lines, MD_SIZE n_lines, int table_m
continue;
}

/* A potential strikethrough start/end. */
if(ch == _T('~')) {
/* A potential strikethrough/equation start/end. */
if(ch == _T('$') || ch == _T('~')) {
OFF tmp = off+1;

while(tmp < line->end && CH(tmp) == _T('~'))
tmp++;

if(tmp - off < 3) {
unsigned flags = 0;

if(tmp < line->end && !ISUNICODEWHITESPACE(tmp))
flags |= MD_MARK_POTENTIAL_OPENER;
if(off > line->beg && !ISUNICODEWHITESPACEBEFORE(off))
flags |= MD_MARK_POTENTIAL_CLOSER;
if(flags != 0)
ADD_MARK(ch, off, tmp, flags);
}

off = tmp;
continue;
}

/* A potential equation start/end */
if(ch == _T('$')) {
/* We can have at most two consecutive $ signs,
* where two dollar signs signify a display equation. */
OFF tmp = off+1;

while(tmp < line->end && CH(tmp) == _T('$'))
while(tmp < line->end && CH(tmp) == ch)
tmp++;

if(tmp - off <= 2) {
Expand Down
14 changes: 14 additions & 0 deletions test/regressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -726,3 +726,17 @@ https://example.com/dir/
.
--fpermissive-url-autolinks
````````````````````````````````


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

```````````````````````````````` example
copy ~user1/file to ~user2/file

copy "~user1/file" to "~user2/file"
.
<p>copy ~user1/file to ~user2/file</p>
<p>copy &quot;~user1/file&quot; to &quot;~user2/file&quot;</p>
.
--fstrikethrough
````````````````````````````````

0 comments on commit 3848bfb

Please sign in to comment.