Repository navigation
fix: close emphasis before a tilde after punctuation in GFM - #4298
Open
phatstraws wants to merge 1 commit into
Open
phatstraws wants to merge 1 commit into
phatstraws wants to merge 1 commit into
Conversation
With gfm on, ~ counts as a letter next to an emphasis delimiter so that *~~a~~*b closes like GitHub does. That also made a closing delimiter that follows punctuation and precedes ~ look like an opener only, so **Note:**~ and **Price:**~$5 stayed literal. Look past a run of ~ when checking the character after a closing * delimiter, which is how cmark-gfm treats the tildes.
|
@phatstraws is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
atishay-kasliwal
left a comment
There was a problem hiding this comment.
Compared GFM output with cmark-gfm on 326 inputs: *, **, _ and __ emphasis around plain, punctuation-ending and quoted text, followed by ~, ~~, ~$5, ~x, strikethrough and so on. Master differed from cmark-gfm on 136 of them and this branch on 40, with none getting worse. The remaining 40 are all _ / __ emphasis followed by ~ and a letter, which cmark-gfm doesn't emphasize; they're the same on master.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Marked version: 18.3.0 (master
fe0d349)Markdown flavor: GitHub Flavored Markdown
Description
With
gfm: true, bold or italic text that ends in punctuation does not close when a~follows it:Expectation
Same as GitHub and the
gfmreference on the demo page:Result
With
gfm: falsethe same input renders correctly, and dropping the~also fixes it.Cause
#3569 and #3577 made
~count as a non-punctuation character next to a*delimiter in GFM, so*~~a~~*bcloses. On the other side of the delimiter that also applies: in**Note:**~the closing**sits between:and~, which matches rule (3) ofemStrongRDelimAst(punctuation before, non-punctuation after) and is taken as a left delimiter only.cmark-gfm handles this by looking past a run of
~when it checks the characters around a delimiter. This change does that for the character after a delimiter inemStrongRDelimAstGfm: each lookahead now skips~*before classifying the next character. The character before the delimiter keeps the current~-as-letter handling, so thestrikethrough_in_em_strongcases are unchanged.**ETA:**~3 daysstays literal, which is also what GitHub does, since the closer is followed by a digit once the tilde is skipped.Only the GFM
*closer regex changes. CommonMark, pedantic and_rules are untouched.npm run test:recheck -- inline.gfm.emStrongRDelimAstreports the new regex as safe.Contributor
test/specs/new/em_strong_before_tilde.mdfails on master and passes with this change.npm run test:specs(2059) andnpm run test:unit(288) pass, andnpm run test:lintis clean.Committer
In most cases, this should be a different person than the contributor.