Skip to content
13 changes: 4 additions & 9 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]|[^\\\(\)])*\))*\)/)
Expand Down Expand Up @@ -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)
Expand All @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions test/specs/new/del_flanking.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 4 additions & 0 deletions test/specs/new/del_flanking.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 4 additions & 0 deletions test/specs/new/del_strikethrough.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@

<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 changes: 4 additions & 0 deletions test/specs/new/del_strikethrough.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ test~~

test~~

~1 a~2

~~1 a~~2

~~~test~~~