@@ -249,27 +249,40 @@ const _notPunctuationOrSpace = /[^\s\p{P}\p{S}]/u;
249249const punctuation = edit ( / ^ ( (? ! [ * _ ] ) p u n c t S p a c e ) / , 'u' )
250250 . replace ( / p u n c t S p a c e / g, _punctuationOrSpace ) . getRegex ( ) ;
251251
252+ // GFM allows ~ inside strong and em for strikethrough
253+ const _punctuationGfmStrongEm = / (? ! ~ ) [ \p{ P} \p{ S} ] / u;
254+ const _punctuationOrSpaceGfmStrongEm = / (? ! ~ ) [ \s \p{ P} \p{ S} ] / u;
255+ const _notPunctuationOrSpaceGfmStrongEm = / (?: [ ^ \s \p{ P} \p{ S} ] | ~ ) / u;
256+
252257// sequences em should skip over [title](link), `code`, <html>
253258const blockSkip = / \[ [ ^ [ \] ] * ?\] \( (?: \\ .| [ ^ \\ \( \) ] | \( (?: \\ .| [ ^ \\ \( \) ] ) * \) ) * \) | ` [ ^ ` ] * ?` | < [ ^ < > ] * ?> / g;
254259
255260const emStrongLDelim = edit ( / ^ (?: \* + (?: ( (? ! \* ) p u n c t ) | [ ^ \s * ] ) ) | ^ _ + (?: ( (? ! _ ) p u n c t ) | ( [ ^ \s _ ] ) ) / , 'u' )
256261 . replace ( / p u n c t / g, _punctuation )
257262 . getRegex ( ) ;
258263
259- const emStrongRDelimAst = edit (
264+ const emStrongRDelimAstCore =
260265 '^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong
261266+ '|[^*]+(?=[^*])' // Consume to delim
262267+ '|(?!\\*)punct(\\*+)(?=[\\s]|$)' // (1) #*** can only be a Right Delimiter
263268+ '|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)' // (2) a***#, a*** can only be a Right Delimiter
264269+ '|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)' // (3) #***a, ***a can only be Left Delimiter
265270+ '|[\\s](\\*+)(?!\\*)(?=punct)' // (4) ***# can only be Left Delimiter
266271+ '|(?!\\*)punct(\\*+)(?!\\*)(?=punct)' // (5) #***# can be either Left or Right Delimiter
267- + '|notPunctSpace(\\*+)(?=notPunctSpace)' , 'gu' ) // (6) a***a can be either Left or Right Delimiter
272+ + '|notPunctSpace(\\*+)(?=notPunctSpace)' ; // (6) a***a can be either Left or Right Delimiter
273+
274+ const emStrongRDelimAst = edit ( emStrongRDelimAstCore , 'gu' )
268275 . replace ( / n o t P u n c t S p a c e / g, _notPunctuationOrSpace )
269276 . replace ( / p u n c t S p a c e / g, _punctuationOrSpace )
270277 . replace ( / p u n c t / g, _punctuation )
271278 . getRegex ( ) ;
272279
280+ const emStrongRDelimAstGfm = edit ( emStrongRDelimAstCore , 'gu' )
281+ . replace ( / n o t P u n c t S p a c e / g, _notPunctuationOrSpaceGfmStrongEm )
282+ . replace ( / p u n c t S p a c e / g, _punctuationOrSpaceGfmStrongEm )
283+ . replace ( / p u n c t / g, _punctuationGfmStrongEm )
284+ . getRegex ( ) ;
285+
273286// (6) Not allowed for _
274287const emStrongRDelimUnd = edit (
275288 '^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)' // Skip orphan inside strong
@@ -375,7 +388,7 @@ const inlinePedantic: Record<InlineKeys, RegExp> = {
375388
376389const inlineGfm : Record < InlineKeys , RegExp > = {
377390 ...inlineNormal ,
378- escape : edit ( escape ) . replace ( '])' , '~|])' ) . getRegex ( ) ,
391+ emStrongRDelimAst : emStrongRDelimAstGfm ,
379392 url : edit ( / ^ ( (?: f t p | h t t p s ? ) : \/ \/ | w w w \. ) (?: [ a - z A - Z 0 - 9 \- ] + \. ? ) + [ ^ \s < ] * | ^ e m a i l / , 'i' )
380393 . replace ( 'email' , / [ A - Z a - z 0 - 9 . _ + - ] + ( @ ) [ a - z A - Z 0 - 9 - _ ] + (?: \. [ a - z A - Z 0 - 9 - _ ] * [ a - z A - Z 0 - 9 ] ) + (? ! [ - _ ] ) / )
381394 . getRegex ( ) ,
0 commit comments