18 lines
558 B
JavaScript
18 lines
558 B
JavaScript
|
const marked = require('marked');
|
||
|
const createDOMPurify = require('dompurify');
|
||
|
const { JSDOM } = require('jsdom');
|
||
|
|
||
|
//This function parses Markdown input, converts it to HTML, and then sanitizes it for security reasons since this input text comes from the user
|
||
|
async function parseMarkdown(inputText) {
|
||
|
let parsedMD = marked.parse(inputText);
|
||
|
|
||
|
const window = new JSDOM('').window;
|
||
|
const DOMPurify = createDOMPurify(window);
|
||
|
const cleanHTML = DOMPurify.sanitize(parsedMD);
|
||
|
|
||
|
return await cleanHTML;
|
||
|
}
|
||
|
|
||
|
module.exports= {
|
||
|
parseMarkdown
|
||
|
}
|