fix: prevent single-tilde strikethrough false positives (#3910)

Co-authored-by: Nikita Barinov <diadorer@nebius.com>
Co-authored-by: Tony Brix <tony@brix.ninja>
This commit is contained in:
Nikita Barinov
2026-03-20 09:06:48 -06:00
committed by GitHub
co-authored by Nikita Barinov Tony Brix
parent 288349d9b6
commit 5e03369db4
5 changed files with 18 additions and 9 deletions
+4 -9
View File
@@ -277,11 +277,6 @@ const _punctuationGfmStrongEm = /(?!~)[\p{P}\p{S}]/u;
const _punctuationOrSpaceGfmStrongEm = /(?!~)[\s\p{P}\p{S}]/u;
const _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u;
// GFM allows * and _ inside strikethrough
const _punctuationGfmDel = /(?![*_])[\p{P}\p{S}]/u;
const _punctuationOrSpaceGfmDel = /(?![*_])[\s\p{P}\p{S}]/u;
const _notPunctuationOrSpaceGfmDel = /(?:[^\s\p{P}\p{S}]|[*_])/u;
// sequences em should skip over [title](link), `code`, <html>
const blockSkip = edit(/link|precode-code|html/, 'g')
.replace('link', /\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/)
@@ -338,7 +333,7 @@ const emStrongRDelimUnd = edit(
// Tilde left delimiter for strikethrough (similar to emStrongLDelim for asterisk)
const delLDelim = edit(/^~~?(?:((?!~)punct)|[^\s~])/, 'u')
.replace(/punct/g, _punctuationGfmDel)
.replace(/punct/g, _punctuation)
.getRegex();
// Tilde delimiter patterns for strikethrough (similar to asterisk)
@@ -352,9 +347,9 @@ const delRDelimCore =
+ '|notPunctSpace(~~?)(?=notPunctSpace)'; // (6) a~~a can be either Left or Right Delimiter
const delRDelim = edit(delRDelimCore, 'gu')
.replace(/notPunctSpace/g, _notPunctuationOrSpaceGfmDel)
.replace(/punctSpace/g, _punctuationOrSpaceGfmDel)
.replace(/punct/g, _punctuationGfmDel)
.replace(/notPunctSpace/g, _notPunctuationOrSpace)
.replace(/punctSpace/g, _punctuationOrSpace)
.replace(/punct/g, _punctuation)
.getRegex();
const anyPunctuation = edit(/\\(punct)/, 'gu')
+2
View File
@@ -3,3 +3,5 @@
<p>Between (~1.34) and (~5.4)</p>
<p>~ test~</p>
<p>~test ~</p>
<p>The mass of the Higgs boson is ~125 GeV, while the top quark is <strong>~173 GeV</strong></p>
<p>~~1 <strong>~~2</strong></p>
+4
View File
@@ -7,3 +7,7 @@ Between (~1.34) and (~5.4)
~ test~
~test ~
The mass of the Higgs boson is ~125 GeV, while the top quark is **~173 GeV**
~~1 **~~2**
+4
View File
@@ -13,4 +13,8 @@ test</del></p>
<p>test~~</p>
<p><del>1 a</del>2</p>
<p><del>1 a</del>2</p>
<pre><code class="language-test~~~"></code></pre>
+4
View File
@@ -13,4 +13,8 @@ test~~
test~~
~1 a~2
~~1 a~~2
~~~test~~~