import marked from 'marked';
import htmlclean from 'htmlclean';
import he from 'he';

const renderer = new marked.Renderer();

renderer.listitem = (text) => {
  if (/<input[^>]+type="checkbox"/.test(text)) {
    return `<li class="task-list-item">${text}</li>\n`;
  }
  return `<li>${text}</li>\n`;
};

renderer.code = (code, language) => {
  const escapedCode = he.escape(code);
  return `<pre${language ? ` data-language="${language}"` : ''}>${escapedCode}</pre>`;
};

renderer.paragraph = (text) => `<div>${text}</div>\n`;

renderer.blockquote = (text) => {
  return `<blockquote>${text.replace(/\n$/, '').split('\n').join('<br />')}</blockquote>`;
};

marked.setOptions({
  gfm: true,
  smartLists: true,
  xhtml: true,
  renderer
});

const markdownToHTML = (markdown) => htmlclean(marked(markdown));

export default markdownToHTML;

@@ -457,16 +457,18 @@
 e%7D%3C/pre%3E
+%5Cn
 %60;%0A%7D;%0A%0Ar
@@ -644,16 +644,18 @@
 ckquote%3E
+%5Cn
 %60;%0A%7D;%0A%0Am

Add line break code at end of marked custom parser result