I want to convert only bold, italic, underline and link to markdown and ignore other rules mentioned by the lexer.
How do i achieve this?
I could not find a example on the extensibility page.
Can someone help me with this?
I want to ignore all rules except above mentioned four conditions.
You can create your own renderer and replace all other render functions to just return the text.
const marked = require('marked');
const renderer = new marked.Renderer();
renderer.code =
renderer.blockquote =
renderer.html =
renderer.heading =
renderer.hr =
renderer.list =
renderer.listitem =
renderer.checkbox =
renderer.paragraph =
renderer.table =
renderer.tablerow =
renderer.tablecell =
renderer.codespan =
renderer.br =
renderer.del =
renderer.image = function (text) {
return text;
};
console.log(marked(markdownString, { renderer: renderer }));
It could be really great to have an out-of-the-box solution for this scenario. For the time being, I settled on using the following approach:
const enabled = ['list', 'listitem', 'strong', 'em', 'paragraph', 'br'];
const renderer = new marked.TextRenderer();
const realRenderer = new marked.Renderer();
enabled.forEach((option) => {
renderer[option] = realRenderer[option];
});
Related: #420
Most helpful comment
It could be really great to have an out-of-the-box solution for this scenario. For the time being, I settled on using the following approach: