Skip to content
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

Ignore certain rules defined by markdown. #1302

Closed
priyesh-diukar opened this issue Jul 2, 2018 · 3 comments
Closed

Ignore certain rules defined by markdown. #1302

priyesh-diukar opened this issue Jul 2, 2018 · 3 comments

Comments

@priyesh-diukar
Copy link

priyesh-diukar commented Jul 2, 2018

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.

@UziTech
Copy link
Member

UziTech commented Jul 2, 2018

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 }));

@denisftw
Copy link

denisftw commented Jul 26, 2018

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];
});

@styfle
Copy link
Member

styfle commented Aug 20, 2018

Related: #420

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants