fix: punctuation regex syntax compatibility#3229
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
| // list of unicode punctuation marks, plus any missing characters from CommonMark spec | ||
| const _punctuation = '\\p{P}\\p{S}'; | ||
| // fallback to explicit punctuation list if runtime environment doesn't support punctuation regex syntax | ||
| const _punctuation = isSupportPunctuationRegex ? '\\p{P}\\p{S}' : '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'; |
There was a problem hiding this comment.
These two regular expressions are very different which means markdown will render differently in different browsers.
You should be able to just change the string to a regular expression. Then babel can transpile it correctly.
- const _punctuation = '\\p{P}\\p{S}';
+ const _punctuation = /\p{P}\p{S}/u;| "@arethetypeswrong/cli": "^0.15.1", | ||
| "@babel/plugin-transform-unicode-regex": "^7.23.3", | ||
| "@markedjs/testutils": "12.0.0-0", | ||
| "@rollup/plugin-babel": "^6.0.4", |
There was a problem hiding this comment.
We don't want to use babel for the output. This will make marked a lot slower and a lot bigger. If users need to support older browsers they can use babel themselves.
There was a problem hiding this comment.
If it's better to inline the transformed regex and use it as a downgrade if users browser is too old?
There was a problem hiding this comment.
Actually I think babel here is just to transform the unicode regex, won't do other stuff 🤔
| .getRegex(); | ||
| const emStrongLDelim = /^(?:\*+(?:((?!\*)[\p{P}\p{S}])|[^\s*]))|^_+(?:((?!_)[\p{P}\p{S}])|([^\s_]))/u; | ||
|
|
||
| const emStrongRDelimAst = /^[^_*]*?__[^_*]*?\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\*)[\p{P}\p{S}](\*+)(?=[\s]|$)|[^\p{P}\p{S}\s](\*+)(?!\*)(?=[\p{P}\p{S}\s]|$)|(?!\*)[\p{P}\p{S}\s](\*+)(?=[^\p{P}\p{S}\s])|[\s](\*+)(?!\*)(?=[\p{P}\p{S}])|(?!\*)[\p{P}\p{S}](\*+)(?!\*)(?=[\p{P}\p{S}])|[^\p{P}\p{S}\s](\*+)(?=[^\p{P}\p{S}\s])/gu; |
There was a problem hiding this comment.
I don't think you need to change this regex since babel will replace the regex in _punctuation with a longer regex then replace will use that regex for punct
There was a problem hiding this comment.
hmm. Then it seems to me that it is not worth the extra work to support browsers that are > 50 versions behind
There was a problem hiding this comment.
Then I'll just close this PR. Thanks
Marked version: 12.0.1
Markdown flavor: Markdown.pl|CommonMark|GitHub Flavored Markdown|n/a
Description
In some runtime environment, the punctuation regex syntax is not supported. Here's an example in Lark app.
Expectation
Marked should work fine in most cases.
Result
Host environment reports error due to unsupported regex syntax.
What was attempted
Nothing can't be executed correctly.
Contributor
Committer
In most cases, this should be a different person than the contributor.