Repository navigation
fix: keep duplicate link definitions in the tokens - #4132
Open
wahidrizka wants to merge 1 commit into
Open
wahidrizka wants to merge 1 commit into
wahidrizka wants to merge 1 commit into
Conversation
A definition whose label was already defined was left out of the token list, so its text was in no token and the raw values of the top-level tokens no longer added up to the source. Keep it as a def token; links still takes the first definition of each label.
|
@wahidrizka is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully 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.1.0 (6a57018)
Markdown flavor: CommonMark|GitHub Flavored Markdown
Description
When a label is defined twice, the lexer stores only the first definition in
links, as CommonMark says, but it also leaves the laterdeftoken out of the token list. Its text is then in no token, so the top-levelrawvalues no longer join back to the source, although the docs describerawas all of the text the token consumes. Spec examples #204 and #544 show it:The newline after a dropped definition is attached to the token before it, or becomes a
spacetoken when there is none, which can make a list item loose:Expectation
as commonmark.js renders it.
Result
What was attempted
Found by checking that the raw values of the top-level tokens join back to the source: of the 652 CommonMark and 28 GFM spec examples, only #204 and #544 fail, both for this reason.
Now the
deftoken is pushed for every definition, andlinksstill keeps only the first one of a label.renderer.defreturns an empty string, so the HTML changes only where a dropped definition had changed the structure around it. In my tests that was list items like the one above, and lazy lines after such a definition in a blockquote, which ended the blockquote. On 20,000 distinct generated documents withgfm: false, 54 render differently: 47 now match commonmark.js and did not before, 7 match it neither before nor after, and none stopped matching. The spec examples render the same as before. Customdefrenderers andwalkTokensnow also get the later definitions.(Edited: my first numbers counted some generated documents twice. These are from 20,000 distinct documents.)
The new
duplicate labellexer test andtest/specs/new/def_duplicate_labelboth fail on master. Specs, unit, umd, cjs, types and lint pass locally, except the fivebinexec tests, which fail on master too because my checkout path has a space in it.Contributor
Committer
In most cases, this should be a different person than the contributor.