@@ -243,42 +243,48 @@ const br = /^( {2,}|\\)\n(?!\s*$)/;
243243const inlineText = / ^ ( ` + | [ ^ ` ] ) (?: (? = { 2 , } \n ) | [ \s \S ] * ?(?: (? = [ \\ < ! \[ ` * _ ] | \b _ | $ ) | [ ^ ] (? = { 2 , } \n ) ) ) / ;
244244
245245// 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 ( ) ;
249251
250252// sequences em should skip over [title](link), `code`, <html>
251253const blockSkip = / \[ [ ^ [ \] ] * ?\] \( (?: \\ .| [ ^ \\ \( \) ] | \( (?: \\ .| [ ^ \\ \( \) ] ) * \) ) * \) | ` [ ^ ` ] * ?` | < [ ^ < > ] * ?> / g;
252254
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' )
254256 . replace ( / p u n c t / g, _punctuation )
255257 . getRegex ( ) ;
256258
257259const emStrongRDelimAst = edit (
258260 '^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong
259261+ '|[^*]+(?=[^*])' // 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 )
266270 . replace ( / p u n c t / g, _punctuation )
267271 . getRegex ( ) ;
268272
269273// (6) Not allowed for _
270274const emStrongRDelimUnd = edit (
271275 '^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)' // Skip orphan inside strong
272276+ '|[^_]+(?=[^_])' // 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 )
278284 . replace ( / p u n c t / g, _punctuation )
279285 . getRegex ( ) ;
280286
281- const anyPunctuation = edit ( / \\ ( [ p u n c t ] ) / , 'gu' )
287+ const anyPunctuation = edit ( / \\ ( p u n c t ) / , 'gu' )
282288 . replace ( / p u n c t / g, _punctuation )
283289 . getRegex ( ) ;
284290
0 commit comments