@@ -243,42 +243,48 @@ const br = /^( {2,}|\\)\n(?!\s*$)/;
243
243
const inlineText = / ^ ( ` + | [ ^ ` ] ) (?: (? = { 2 , } \n ) | [ \s \S ] * ?(?: (? = [ \\ < ! \[ ` * _ ] | \b _ | $ ) | [ ^ ] (? = { 2 , } \n ) ) ) / ;
244
244
245
245
// list of unicode punctuation marks, plus any missing characters from CommonMark spec
246
- const _punctuation = / \p{ P} \p{ S} / u;
247
- const punctuation = edit ( / ^ ( (? ! [ * _ ] ) [ \s p u n c t u a t i o n ] ) / , 'u' )
248
- . replace ( / p u n c t u a t i o n / g, _punctuation ) . getRegex ( ) ;
246
+ const _punctuation = / [ \p{ P} \p{ S} ] / u;
247
+ const _punctuationOrSpace = / [ \s \p{ P} \p{ S} ] / u;
248
+ const _notPunctuationOrSpace = / [ ^ \s \p{ P} \p{ S} ] / u;
249
+ const punctuation = edit ( / ^ ( (? ! [ * _ ] ) p u n c t S p a c e ) / , 'u' )
250
+ . replace ( / p u n c t S p a c e / g, _punctuationOrSpace ) . getRegex ( ) ;
249
251
250
252
// sequences em should skip over [title](link), `code`, <html>
251
253
const blockSkip = / \[ [ ^ [ \] ] * ?\] \( (?: \\ .| [ ^ \\ \( \) ] | \( (?: \\ .| [ ^ \\ \( \) ] ) * \) ) * \) | ` [ ^ ` ] * ?` | < [ ^ < > ] * ?> / g;
252
254
253
- const emStrongLDelim = edit ( / ^ (?: \* + (?: ( (? ! \* ) [ p u n c t ] ) | [ ^ \s * ] ) ) | ^ _ + (?: ( (? ! _ ) [ p u n c t ] ) | ( [ ^ \s _ ] ) ) / , 'u' )
255
+ const emStrongLDelim = edit ( / ^ (?: \* + (?: ( (? ! \* ) p u n c t ) | [ ^ \s * ] ) ) | ^ _ + (?: ( (? ! _ ) p u n c t ) | ( [ ^ \s _ ] ) ) / , 'u' )
254
256
. replace ( / p u n c t / g, _punctuation )
255
257
. getRegex ( ) ;
256
258
257
259
const emStrongRDelimAst = edit (
258
260
'^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong
259
261
+ '|[^*]+(?=[^*])' // Consume to delim
260
- + '|(?!\\*)[punct](\\*+)(?=[\\s]|$)' // (1) #*** can only be a Right Delimiter
261
- + '|[^punct\\s](\\*+)(?!\\*)(?=[punct\\s]|$)' // (2) a***#, a*** can only be a Right Delimiter
262
- + '|(?!\\*)[punct\\s](\\*+)(?=[^punct\\s])' // (3) #***a, ***a can only be Left Delimiter
263
- + '|[\\s](\\*+)(?!\\*)(?=[punct])' // (4) ***# can only be Left Delimiter
264
- + '|(?!\\*)[punct](\\*+)(?!\\*)(?=[punct])' // (5) #***# can be either Left or Right Delimiter
265
- + '|[^punct\\s](\\*+)(?=[^punct\\s])' , 'gu' ) // (6) a***a can be either Left or Right Delimiter
262
+ + '|(?!\\*)punct(\\*+)(?=[\\s]|$)' // (1) #*** can only be a Right Delimiter
263
+ + '|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)' // (2) a***#, a*** can only be a Right Delimiter
264
+ + '|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)' // (3) #***a, ***a can only be Left Delimiter
265
+ + '|[\\s](\\*+)(?!\\*)(?=punct)' // (4) ***# can only be Left Delimiter
266
+ + '|(?!\\*)punct(\\*+)(?!\\*)(?=punct)' // (5) #***# can be either Left or Right Delimiter
267
+ + '|notPunctSpace(\\*+)(?=notPunctSpace)' , 'gu' ) // (6) a***a can be either Left or Right Delimiter
268
+ . replace ( / n o t P u n c t S p a c e / g, _notPunctuationOrSpace )
269
+ . replace ( / p u n c t S p a c e / g, _punctuationOrSpace )
266
270
. replace ( / p u n c t / g, _punctuation )
267
271
. getRegex ( ) ;
268
272
269
273
// (6) Not allowed for _
270
274
const emStrongRDelimUnd = edit (
271
275
'^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)' // Skip orphan inside strong
272
276
+ '|[^_]+(?=[^_])' // Consume to delim
273
- + '|(?!_)[punct](_+)(?=[\\s]|$)' // (1) #___ can only be a Right Delimiter
274
- + '|[^punct\\s](_+)(?!_)(?=[punct\\s]|$)' // (2) a___#, a___ can only be a Right Delimiter
275
- + '|(?!_)[punct\\s](_+)(?=[^punct\\s])' // (3) #___a, ___a can only be Left Delimiter
276
- + '|[\\s](_+)(?!_)(?=[punct])' // (4) ___# can only be Left Delimiter
277
- + '|(?!_)[punct](_+)(?!_)(?=[punct])' , 'gu' ) // (5) #___# can be either Left or Right Delimiter
277
+ + '|(?!_)punct(_+)(?=[\\s]|$)' // (1) #___ can only be a Right Delimiter
278
+ + '|notPunctSpace(_+)(?!_)(?=punctSpace|$)' // (2) a___#, a___ can only be a Right Delimiter
279
+ + '|(?!_)punctSpace(_+)(?=notPunctSpace)' // (3) #___a, ___a can only be Left Delimiter
280
+ + '|[\\s](_+)(?!_)(?=punct)' // (4) ___# can only be Left Delimiter
281
+ + '|(?!_)punct(_+)(?!_)(?=punct)' , 'gu' ) // (5) #___# can be either Left or Right Delimiter
282
+ . replace ( / n o t P u n c t S p a c e / g, _notPunctuationOrSpace )
283
+ . replace ( / p u n c t S p a c e / g, _punctuationOrSpace )
278
284
. replace ( / p u n c t / g, _punctuation )
279
285
. getRegex ( ) ;
280
286
281
- const anyPunctuation = edit ( / \\ ( [ p u n c t ] ) / , 'gu' )
287
+ const anyPunctuation = edit ( / \\ ( p u n c t ) / , 'gu' )
282
288
. replace ( / p u n c t / g, _punctuation )
283
289
. getRegex ( ) ;
284
290
0 commit comments