diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index 52a4a377f..a040a1e79 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -13,6 +13,52 @@ renderer.html = function (html) { return html; }; +renderer.link = function (href, title, text) { + let self = false; + if(href[0] == '#') { + self = true; + } + href = cleanUrl(this.options.sanitize, this.options.baseUrl, href); + console.log(href); + console.log(this.options.sanitize); + if(href === null) { + return text; + } + let out = `${text}`; + console.log(out); + return out; +}; + +const nonWordAndColonTest = /[^\w:]/g; +const cleanUrl = function (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; + } + } + try { + href = encodeURI(href).replace(/%25/g, '%'); + } catch (e) { + return null; + } + return href; +}; + const sanatizeScriptTags = (content)=>{ return content .replace(/