@@ -249,27 +249,40 @@ const _notPunctuationOrSpace = /[^\s\p{P}\p{S}]/u;
249
249
const punctuation = edit ( / ^ ( (? ! [ * _ ] ) p u n c t S p a c e ) / , 'u' )
250
250
. replace ( / p u n c t S p a c e / g, _punctuationOrSpace ) . getRegex ( ) ;
251
251
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
+
252
257
// sequences em should skip over [title](link), `code`, <html>
253
258
const blockSkip = / \[ [ ^ [ \] ] * ?\] \( (?: \\ .| [ ^ \\ \( \) ] | \( (?: \\ .| [ ^ \\ \( \) ] ) * \) ) * \) | ` [ ^ ` ] * ?` | < [ ^ < > ] * ?> / g;
254
259
255
260
const emStrongLDelim = edit ( / ^ (?: \* + (?: ( (? ! \* ) p u n c t ) | [ ^ \s * ] ) ) | ^ _ + (?: ( (? ! _ ) p u n c t ) | ( [ ^ \s _ ] ) ) / , 'u' )
256
261
. replace ( / p u n c t / g, _punctuation )
257
262
. getRegex ( ) ;
258
263
259
- const emStrongRDelimAst = edit (
264
+ const emStrongRDelimAstCore =
260
265
'^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong
261
266
+ '|[^*]+(?=[^*])' // Consume to delim
262
267
+ '|(?!\\*)punct(\\*+)(?=[\\s]|$)' // (1) #*** can only be a Right Delimiter
263
268
+ '|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)' // (2) a***#, a*** can only be a Right Delimiter
264
269
+ '|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)' // (3) #***a, ***a can only be Left Delimiter
265
270
+ '|[\\s](\\*+)(?!\\*)(?=punct)' // (4) ***# can only be Left Delimiter
266
271
+ '|(?!\\*)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' )
268
275
. replace ( / n o t P u n c t S p a c e / g, _notPunctuationOrSpace )
269
276
. replace ( / p u n c t S p a c e / g, _punctuationOrSpace )
270
277
. replace ( / p u n c t / g, _punctuation )
271
278
. getRegex ( ) ;
272
279
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
+
273
286
// (6) Not allowed for _
274
287
const emStrongRDelimUnd = edit (
275
288
'^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)' // Skip orphan inside strong
@@ -375,7 +388,7 @@ const inlinePedantic: Record<InlineKeys, RegExp> = {
375
388
376
389
const inlineGfm : Record < InlineKeys , RegExp > = {
377
390
...inlineNormal ,
378
- escape : edit ( escape ) . replace ( '])' , '~|])' ) . getRegex ( ) ,
391
+ emStrongRDelimAst : emStrongRDelimAstGfm ,
379
392
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' )
380
393
. 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 ] ) + (? ! [ - _ ] ) / )
381
394
. getRegex ( ) ,
0 commit comments