Skip to content

Commit 5e03369

Browse files
diadorerNikita BarinovUziTech
authored
fix: prevent single-tilde strikethrough false positives (#3910)
Co-authored-by: Nikita Barinov <diadorer@nebius.com> Co-authored-by: Tony Brix <tony@brix.ninja>
1 parent 288349d commit 5e03369

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

src/rules.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,6 @@ const _punctuationGfmStrongEm = /(?!~)[\p{P}\p{S}]/u;
277277
const _punctuationOrSpaceGfmStrongEm = /(?!~)[\s\p{P}\p{S}]/u;
278278
const _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u;
279279

280-
// GFM allows * and _ inside strikethrough
281-
const _punctuationGfmDel = /(?![*_])[\p{P}\p{S}]/u;
282-
const _punctuationOrSpaceGfmDel = /(?![*_])[\s\p{P}\p{S}]/u;
283-
const _notPunctuationOrSpaceGfmDel = /(?:[^\s\p{P}\p{S}]|[*_])/u;
284-
285280
// sequences em should skip over [title](link), `code`, <html>
286281
const blockSkip = edit(/link|precode-code|html/, 'g')
287282
.replace('link', /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/)
@@ -338,7 +333,7 @@ const emStrongRDelimUnd = edit(
338333

339334
// Tilde left delimiter for strikethrough (similar to emStrongLDelim for asterisk)
340335
const delLDelim = edit(/^~~?(?:((?!~)punct)|[^\s~])/, 'u')
341-
.replace(/punct/g, _punctuationGfmDel)
336+
.replace(/punct/g, _punctuation)
342337
.getRegex();
343338

344339
// Tilde delimiter patterns for strikethrough (similar to asterisk)
@@ -352,9 +347,9 @@ const delRDelimCore =
352347
+ '|notPunctSpace(~~?)(?=notPunctSpace)'; // (6) a~~a can be either Left or Right Delimiter
353348

354349
const delRDelim = edit(delRDelimCore, 'gu')
355-
.replace(/notPunctSpace/g, _notPunctuationOrSpaceGfmDel)
356-
.replace(/punctSpace/g, _punctuationOrSpaceGfmDel)
357-
.replace(/punct/g, _punctuationGfmDel)
350+
.replace(/notPunctSpace/g, _notPunctuationOrSpace)
351+
.replace(/punctSpace/g, _punctuationOrSpace)
352+
.replace(/punct/g, _punctuation)
358353
.getRegex();
359354

360355
const anyPunctuation = edit(/\\(punct)/, 'gu')

test/specs/new/del_flanking.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
<p>Between (~1.34) and (~5.4)</p>
44
<p>~ test~</p>
55
<p>~test ~</p>
6+
<p>The mass of the Higgs boson is ~125 GeV, while the top quark is <strong>~173 GeV</strong></p>
7+
<p>~~1 <strong>~~2</strong></p>

test/specs/new/del_flanking.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ Between (~1.34) and (~5.4)
77
~ test~
88

99
~test ~
10+
11+
The mass of the Higgs boson is ~125 GeV, while the top quark is **~173 GeV**
12+
13+
~~1 **~~2**

test/specs/new/del_strikethrough.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@
1313

1414
<p>test~~</p>
1515

16+
<p><del>1 a</del>2</p>
17+
18+
<p><del>1 a</del>2</p>
19+
1620
<pre><code class="language-test~~~"></code></pre>

test/specs/new/del_strikethrough.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ test~~
1313

1414
test~~
1515

16+
~1 a~2
17+
18+
~~1 a~~2
19+
1620
~~~test~~~

0 commit comments

Comments
 (0)