fix: parse pedantic strong punctuation#3959
fix: parse pedantic strong punctuation#3959lawrence3699 wants to merge 1 commit intomarkedjs:masterfrom
Conversation
|
@lawrence3699 is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
Code Review
This pull request introduces the emStrongRDelimAstPedantic regex to correctly handle asterisk-based strong delimiters in pedantic mode, specifically addressing cases where punctuation precedes the closing delimiter. While this fixes the issue for asterisks, feedback suggests that a similar rule is required for underscore-based delimiters (__) to ensure consistent behavior and parity with Markdown.pl.
| const emStrongRDelimAstPedantic = edit( | ||
| '^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)' // Skip orphan inside strong | ||
| + '|[^*]+(?=[^*])' // Consume to delim | ||
| + '|(?!\\*)punct(\\*+)(?=[\\s]|$)' // (1) #*** can only be a Right Delimiter | ||
| + '|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)' // (2) a***#, a*** can only be a Right Delimiter | ||
| + '|(?!\\*)[\\s](\\*+)(?=notPunctSpace)' // (3) ***a can only be Left Delimiter | ||
| + '|[\\s](\\*+)(?!\\*)(?=punct)' // (4) ***# can only be Left Delimiter | ||
| + '|(?!\\*)punct(\\*+)(?!\\*)(?=punct)' // (5) #***# can be either Left or Right Delimiter | ||
| + '|(?:(?!\\*)punct|notPunctSpace)(\\*+)(?!\\*)(?=notPunctSpace)', 'gu') // (6) #***a and a***a can be either Left or Right Delimiter | ||
| .replace(/notPunctSpace/g, _notPunctuationOrSpace) | ||
| .replace(/punctSpace/g, _punctuationOrSpace) | ||
| .replace(/punct/g, _punctuation) | ||
| .getRegex(); |
There was a problem hiding this comment.
The new emStrongRDelimAstPedantic regex correctly addresses the issue for asterisk delimiters, but the same problem exists for underscores (e.g., __foo:__bar) in pedantic mode.
In Markdown.pl, __foo:__bar is rendered as <strong>foo:</strong>bar. However, since inlinePedantic still uses the default emStrongRDelimUnd rule, it will incorrectly treat :_ followed by a non-space character as a left-only delimiter (due to Rule 3 in emStrongRDelimUnd).
Consider adding a corresponding emStrongRDelimUndPedantic rule and updating inlinePedantic to include it, ensuring consistent behavior for both types of strong delimiters in pedantic mode.
There was a problem hiding this comment.
Can you also add a test for __foo:__bar and make that work as well? Those should work the same.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Marked version:
18.0.2 / master
Markdown flavor: Markdown.pl / pedantic
Description
Fixes #3938.
In pedantic mode,
**foo:**barwas still parsed with CommonMark delimiter rules and rendered as literal asterisks:Markdown.pl renders the same input as:
This adds a pedantic-only asterisk delimiter rule so punctuation before a closing
**can end strong text when the next character is not whitespace. The normal and GFM delimiter rules are unchanged.Contributor
Validation:
npm run build:esbuild && node --test --test-reporter=spec test/run-spec-tests.jsnpm run test:lintnpm testnpm run build:reset