From 38d47f6aa193a95d2e552c6e7d940c09a3688e98 Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Tue, 27 Oct 2020 11:24:07 -0400 Subject: [PATCH] Remove console.log slowing things down. --- shared/naturalcrit/markdown.js | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/shared/naturalcrit/markdown.js b/shared/naturalcrit/markdown.js index a040a1e79..9dc4fa9c9 100644 --- a/shared/naturalcrit/markdown.js +++ b/shared/naturalcrit/markdown.js @@ -19,12 +19,11 @@ renderer.link = function (href, title, text) { 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; }; @@ -59,6 +57,32 @@ const cleanUrl = function (sanitize, base, href) { return href; }; +const escapeTest = /[&<>"']/; +const escapeReplace = /[&<>"']/g; +const escapeTestNoEncode = /[<>"']|&(?!#?\w+;)/; +const escapeReplaceNoEncode = /[<>"']|&(?!#?\w+;)/g; +const escapeReplacements = { + '&' : '&', + '<' : '<', + '>' : '>', + '"' : '"', + '\'' : ''' +}; +const getEscapeReplacement = (ch)=>escapeReplacements[ch]; +const escape = function (html, encode) { + if(encode) { + if(escapeTest.test(html)) { + return html.replace(escapeReplace, getEscapeReplacement); + } + } else { + if(escapeTestNoEncode.test(html)) { + return html.replace(escapeReplaceNoEncode, getEscapeReplacement); + } + } + + return html; +}; + const sanatizeScriptTags = (content)=>{ return content .replace(/