fix: fix strikethrough inside strong and em to follow gfm (#3577)

* fix: fix strikethrough inside strong and em to follow gfm

* add both sides tests
This commit is contained in:
Tony Brix 2025-01-06 08:50:34 -07:00 committed by GitHub
parent 42ac48b9b4
commit 7712a5324f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 72 additions and 1 deletions

View File

@ -257,10 +257,16 @@ const _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u;
// sequences em should skip over [title](link), `code`, <html>
const blockSkip = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g;
const emStrongLDelim = edit(/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/, 'u')
const emStrongLDelimCore = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
const emStrongLDelim = edit(emStrongLDelimCore, 'u')
.replace(/punct/g, _punctuation)
.getRegex();
const emStrongLDelimGfm = edit(emStrongLDelimCore, 'u')
.replace(/punct/g, _punctuationGfmStrongEm)
.getRegex();
const emStrongRDelimAstCore =
'^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong
+ '|[^*]+(?=[^*])' // Consume to delim
@ -389,6 +395,7 @@ const inlinePedantic: Record<InlineKeys, RegExp> = {
const inlineGfm: Record<InlineKeys, RegExp> = {
...inlineNormal,
emStrongRDelimAst: emStrongRDelimAstGfm,
emStrongLDelim: emStrongLDelimGfm,
url: edit(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, 'i')
.replace('email', /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/)
.getRegex(),

View File

@ -13,3 +13,35 @@
<p>__<del>a</del>__b</p>
<p>__<del>a</del>__b</p>
<p>b<em><del>a</del></em></p>
<p>b<em><del>a</del></em></p>
<p>b<strong><del>a</del></strong></p>
<p>b<strong><del>a</del></strong></p>
<p>b_<del>a</del>_</p>
<p>b_<del>a</del>_</p>
<p>b__<del>a</del>__</p>
<p>b__<del>a</del>__</p>
<p>b<em><del>a</del></em>b</p>
<p>b<em><del>a</del></em>b</p>
<p>b<strong><del>a</del></strong>b</p>
<p>b<strong><del>a</del></strong>b</p>
<p>b_<del>a</del>_b</p>
<p>b_<del>a</del>_b</p>
<p>b__<del>a</del>__b</p>
<p>b__<del>a</del>__b</p>

View File

@ -13,3 +13,35 @@ _~~a~~_b
__~a~__b
__~~a~~__b
b*~a~*
b*~~a~~*
b**~a~**
b**~~a~~**
b_~a~_
b_~~a~~_
b__~a~__
b__~~a~~__
b*~a~*b
b*~~a~~*b
b**~a~**b
b**~~a~~**b
b_~a~_b
b_~~a~~_b
b__~a~__b
b__~~a~~__b