Skip to content

Commit 7712a53

Browse files
authored
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
1 parent 42ac48b commit 7712a53

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

src/rules.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,16 @@ const _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u;
257257
// sequences em should skip over [title](link), `code`, <html>
258258
const blockSkip = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g;
259259

260-
const emStrongLDelim = edit(/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/, 'u')
260+
const emStrongLDelimCore = /^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/;
261+
262+
const emStrongLDelim = edit(emStrongLDelimCore, 'u')
261263
.replace(/punct/g, _punctuation)
262264
.getRegex();
263265

266+
const emStrongLDelimGfm = edit(emStrongLDelimCore, 'u')
267+
.replace(/punct/g, _punctuationGfmStrongEm)
268+
.getRegex();
269+
264270
const emStrongRDelimAstCore =
265271
'^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong
266272
+ '|[^*]+(?=[^*])' // Consume to delim
@@ -389,6 +395,7 @@ const inlinePedantic: Record<InlineKeys, RegExp> = {
389395
const inlineGfm: Record<InlineKeys, RegExp> = {
390396
...inlineNormal,
391397
emStrongRDelimAst: emStrongRDelimAstGfm,
398+
emStrongLDelim: emStrongLDelimGfm,
392399
url: edit(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, 'i')
393400
.replace('email', /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/)
394401
.getRegex(),

test/specs/new/strikethrough_in_em_strong.html

+32
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,35 @@
1313
<p>__<del>a</del>__b</p>
1414

1515
<p>__<del>a</del>__b</p>
16+
17+
<p>b<em><del>a</del></em></p>
18+
19+
<p>b<em><del>a</del></em></p>
20+
21+
<p>b<strong><del>a</del></strong></p>
22+
23+
<p>b<strong><del>a</del></strong></p>
24+
25+
<p>b_<del>a</del>_</p>
26+
27+
<p>b_<del>a</del>_</p>
28+
29+
<p>b__<del>a</del>__</p>
30+
31+
<p>b__<del>a</del>__</p>
32+
33+
<p>b<em><del>a</del></em>b</p>
34+
35+
<p>b<em><del>a</del></em>b</p>
36+
37+
<p>b<strong><del>a</del></strong>b</p>
38+
39+
<p>b<strong><del>a</del></strong>b</p>
40+
41+
<p>b_<del>a</del>_b</p>
42+
43+
<p>b_<del>a</del>_b</p>
44+
45+
<p>b__<del>a</del>__b</p>
46+
47+
<p>b__<del>a</del>__b</p>

test/specs/new/strikethrough_in_em_strong.md

+32
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,35 @@ _~~a~~_b
1313
__~a~__b
1414

1515
__~~a~~__b
16+
17+
b*~a~*
18+
19+
b*~~a~~*
20+
21+
b**~a~**
22+
23+
b**~~a~~**
24+
25+
b_~a~_
26+
27+
b_~~a~~_
28+
29+
b__~a~__
30+
31+
b__~~a~~__
32+
33+
b*~a~*b
34+
35+
b*~~a~~*b
36+
37+
b**~a~**b
38+
39+
b**~~a~~**b
40+
41+
b_~a~_b
42+
43+
b_~~a~~_b
44+
45+
b__~a~__b
46+
47+
b__~~a~~__b

0 commit comments

Comments
 (0)