mirror of https://github.com/keeweb/keeweb.git
24 lines
653 B
JavaScript
24 lines
653 B
JavaScript
const marked = require('marked');
|
|
const dompurify = require('dompurify');
|
|
|
|
const whiteSpaceRegex = /<\/?p>|<br>|\r|\n/g;
|
|
|
|
const MdToHtml = {
|
|
convert(md) {
|
|
if (!md) {
|
|
return '';
|
|
}
|
|
const html = marked(md);
|
|
const htmlWithoutLineBreaks = html.replace(whiteSpaceRegex, '');
|
|
const mdWithoutLineBreaks = md.replace(whiteSpaceRegex, '');
|
|
if (htmlWithoutLineBreaks === mdWithoutLineBreaks) {
|
|
return md;
|
|
} else {
|
|
const sanitized = dompurify.sanitize(html);
|
|
return `<div class="markdown">${sanitized}</div>`;
|
|
}
|
|
}
|
|
};
|
|
|
|
module.exports = MdToHtml;
|