Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upCatch-all method for Renderer #1336
Open
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); |
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: