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
Catch-all method for Renderer #1336
Projects
Comments
No, any method that is not overwritten is assumed to be using the default implementation |
Perhaps we could add a function that does that. Something like: const md = require('marked');
const renderer = new md.Renderer();
renderer.all(htmlString => /* set all methods to use this default function */);
// change the methods you want to be different
renderer.heading = (text, level) => // do something with headings;
renderer.paragraph = text => // do something with paragraphs;
md(input, { renderer }, (err, result) => console.log(result); I would be open to a pull request like that. |
It's pretty easy to achieve today without an additional feature. const marked = require('marked');
const renderer = new marked.Renderer();
// Do something for all methods
const all = (str) => { console.log('all', str) };
// Magic to wire-up all methods on the renderer
Object.keys(renderer.__proto__).forEach(p => renderer[p] = all);
// Change the methods you want to be different
renderer.heading = (text, level) => { console.log('heading', text, level) }
renderer.paragraph = text => { console.log('paragraph', text) }
marked(input, { renderer }, (err, result) => console.log(result); |
is this still the best way to implement a catch-all? |
@marco-silva0000 yes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I couldn't find this in the docs, but I was wondering if there was a way to set up some sort of catch-all method for HTML tags that don't match any overwritten renderer methods? For example:
The text was updated successfully, but these errors were encountered: