-
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
marked.use #1646
marked.use #1646
Conversation
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/markedjs/markedjs/2i2a4afnt |
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.
Looks good overall. Perhaps add a sentence in USING_PRO.md to clarify the use case?
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.
I appreciate this solution, agree with @davisjam request for updates to docs, which seems to have happened.
Does this only work for a custom renderer at this time? Is this a reusable pattern for extending other sub-components of Marked?
This can be used to extend any option in marked. The renderer and tokenizer will be merged but all other options will overwrite previous options. |
@davisjam I added a section explaining |
This PR doesn't change current ways of extending marked with It just adds a new method ( |
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.
LGTM, thanks
The idea is to create extensions in the form // some-marked-extension
module.exports = {
renderer: {...},
tokenizer: {...}
}; // some-other-marked-extension
module.exports = {
renderer: {...},
tokenizer: {...}
}; that can be used by users without overriding eachother const marked = require('marked');
marked.use(require('some-marked-extension'));
marked.use(require('some-other-marked-extension'));
... |
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.
Great work 🎉
Marked version: master
Description
Add function
marked.use
which takes an options object and merges it into marked options.The
renderer
andtokenizer
can be an object with functions that will be merged into therenderer
andtokenizer
respectively.The
renderer
andtokenizer
functions can returnfalse
to fallback to the previous function.Contributor
Committer
In most cases, this should be a different person than the contributor.