-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: tokenizer extension position #3594
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
I haven't run any benchmarks on this, but I'm curious how much of a slowdown this adds, assuming no extensions. Do you have any measurements? As an alternative that might be more flexible, but more restructuring... I wonder what you think about extracting each of the parser/renderer steps into an array of "extension-like objects". I.e., instead of:
something like (pseudocode):
I'm fairly certain there is some speed impact calling the tokenizers from an array/map/object like this but it might make the whole project more flexible for this type of "extension position" customization. |
I did try to move the tokenizers to some sort of array but there were two problems.
I think just adding a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation seems good to me assuming there's no alternative to the boilerplate.
Remaining comments:
- Should this include a documentation update?
- Does this need a test for an extension at one of the custom positions?
- Is there any significant performance impact? Not sure if the extra function calls between each step are going to be an issue.
if (ext.position && ![...tokenizerBlockPositions, ...tokenizerInlinePositions].includes(ext.position)) { | ||
throw new Error(`extension position must be one of '${tokenizerBlockPositions.join("', '")}', '${tokenizerInlinePositions.join("', '")}'`); | ||
} | ||
if (!ext.level && !ext.position) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we enforce compatible level
and position
entries? I.e., a block
level doesn't make sense with an inline
position. Or, should these properties be mutually-exclusive to avoid unexpected behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are mutually exclusive. They can both be specified in case an extension wants to support many versions of marked, but versions of marked that allow position will ignore level if position is provided.
Ok, fair enough. Looking back, this is what I tried to do back in 2021 and I think we concluded arrays just add too much slowdown anyway. #1872 Also looking back, we had discussed a "before" parameter 4 years ago. Hoping it wasn't also a lag issue that made us drop it #2043 (comment) |
Ya, these 3 are in the TODOs section in this PRs description. I will work on them soon.
Looks like we just figured we would get it done when it was actually needed |
Marked version: 15.0.6
Description
Add
position
property for tokenizer extension to it can pick where to be ran in the lexer.TODO:
Contributor
Committer
In most cases, this should be a different person than the contributor.