marked.use - #1646
Conversation
|
This pull request is being automatically deployed with ZEIT Now (learn more). 🔍 Inspect: https://zeit.co/markedjs/markedjs/2i2a4afnt |
davisjam
left a comment
There was a problem hiding this comment.
Looks good overall. Perhaps add a sentence in USING_PRO.md to clarify the use case?
joshbruce
left a comment
There was a problem hiding this comment.
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 ( |
|
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'));
... |
Marked version: master
Description
Add function
marked.usewhich takes an options object and merges it into marked options.The
rendererandtokenizercan be an object with functions that will be merged into therendererandtokenizerrespectively.The
rendererandtokenizerfunctions can returnfalseto fallback to the previous function.Contributor
Committer
In most cases, this should be a different person than the contributor.