Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
32 changes: 32 additions & 0 deletions test/specs/new/strikethrough_in_em_strong.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@

<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>
32 changes: 32 additions & 0 deletions test/specs/new/strikethrough_in_em_strong.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading