diff --git a/src/rules.ts b/src/rules.ts index d332542c72..ca32f5cd20 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -257,10 +257,16 @@ const _notPunctuationOrSpaceGfmStrongEm = /(?:[^\s\p{P}\p{S}]|~)/u; // sequences em should skip over [title](link), `code`, 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 = { const inlineGfm: Record = { ...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(), diff --git a/test/specs/new/strikethrough_in_em_strong.html b/test/specs/new/strikethrough_in_em_strong.html index d3686dfb46..45a4592085 100644 --- a/test/specs/new/strikethrough_in_em_strong.html +++ b/test/specs/new/strikethrough_in_em_strong.html @@ -13,3 +13,35 @@

__a__b

__a__b

+ +

ba

+ +

ba

+ +

ba

+ +

ba

+ +

b_a_

+ +

b_a_

+ +

b__a__

+ +

b__a__

+ +

bab

+ +

bab

+ +

bab

+ +

bab

+ +

b_a_b

+ +

b_a_b

+ +

b__a__b

+ +

b__a__b

diff --git a/test/specs/new/strikethrough_in_em_strong.md b/test/specs/new/strikethrough_in_em_strong.md index ec5af274ff..024cde92be 100644 --- a/test/specs/new/strikethrough_in_em_strong.md +++ b/test/specs/new/strikethrough_in_em_strong.md @@ -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