Skip to content

Commit 9b988c4

Browse files
WizardMeowjinbowen
and
jinbowen
authored
fix: update punctuation regex syntax to fix babel mistaken transpile (#3547)
Co-authored-by: jinbowen <[email protected]>
1 parent 1521756 commit 9b988c4

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/rules.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -243,42 +243,48 @@ const br = /^( {2,}|\\)\n(?!\s*$)/;
243243
const 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(/^((?![*_])[\spunctuation])/, 'u')
248-
.replace(/punctuation/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(/^((?![*_])punctSpace)/, 'u')
250+
.replace(/punctSpace/g, _punctuationOrSpace).getRegex();
249251

250252
// sequences em should skip over [title](link), `code`, <html>
251253
const blockSkip = /\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g;
252254

253-
const emStrongLDelim = edit(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/, 'u')
255+
const emStrongLDelim = edit(/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/, 'u')
254256
.replace(/punct/g, _punctuation)
255257
.getRegex();
256258

257259
const 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(/notPunctSpace/g, _notPunctuationOrSpace)
269+
.replace(/punctSpace/g, _punctuationOrSpace)
266270
.replace(/punct/g, _punctuation)
267271
.getRegex();
268272

269273
// (6) Not allowed for _
270274
const 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(/notPunctSpace/g, _notPunctuationOrSpace)
283+
.replace(/punctSpace/g, _punctuationOrSpace)
278284
.replace(/punct/g, _punctuation)
279285
.getRegex();
280286

281-
const anyPunctuation = edit(/\\([punct])/, 'gu')
287+
const anyPunctuation = edit(/\\(punct)/, 'gu')
282288
.replace(/punct/g, _punctuation)
283289
.getRegex();
284290

0 commit comments

Comments
 (0)