diff --git a/src/marked/renderer.js b/src/marked/renderer.js new file mode 100644 index 0000000..3716c09 --- /dev/null +++ b/src/marked/renderer.js @@ -0,0 +1,66 @@ +const { marked } = require('marked') + +/** + * + * + */ + +// copy from @marked/src/helpers.js, no export possible +function cleanUrl(sanitize, base, href) { + if (sanitize) { + + let prot + + try { + prot = decodeURIComponent(unescape(href)) + .replace(nonWordAndColonTest, '') + .toLowerCase() + } catch (e) { + return null + } + + if (prot.indexOf('javascript:') === 0 || prot.indexOf('vbscript:') === 0 || prot.indexOf('data:') === 0) { + return null + } + } + + if (base && !originIndependentUrl.test(href)) { + href = resolveUrl(base, href) + } + + try { + href = encodeURI(href).replace(/%25/g, '%') + } catch (e) { + return null + } + + return href +} + +const renderer = { + link(href, title, text) { + + href = cleanUrl(this.options.sanitize, this.options.baseUrl, href) + + if (href === null) { + return text + } + + let out = '' + + return out + } +} + +module.exports = renderer diff --git a/src/parsers/markdown.js b/src/parsers/markdown.js index 8a3cb93..40ade1d 100644 --- a/src/parsers/markdown.js +++ b/src/parsers/markdown.js @@ -1,6 +1,8 @@ const yaml = require('js-yaml') const { marked } = require('marked') +const renderer = require('./../marked/renderer.js') + /** * parse string of file, parse yaml and parse markdown * @@ -33,10 +35,11 @@ function parseMarkdownFile(fileString) { // if markdown section exits parse it to html 6565 if (matches?.[3]) { + marked.use({ renderer }) result.content = marked.parse(matches[3]) } return result } -module.exports = parseMarkdownFile \ No newline at end of file +module.exports = parseMarkdownFile