From 25601fd50a1132094396c4995f827e43ecc44ece Mon Sep 17 00:00:00 2001 From: weru Date: Fri, 17 Dec 2021 18:55:37 +0300 Subject: [PATCH] fix bug: enforce proper image src #15 Signed-off-by: weru --- assets/js/functions.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/assets/js/functions.js b/assets/js/functions.js index dc127927..0d5095bc 100644 --- a/assets/js/functions.js +++ b/assets/js/functions.js @@ -111,6 +111,8 @@ function wrapEl(el, wrapper) { function wrapText(text, context, wrapper = 'mark') { let open = `<${wrapper}>`; let close = ``; + let escapedOpen = `%3C${wrapper}%3E`; + let escapedClose = `%3C/${wrapper}%3E`; function wrap(context) { let c = context.innerHTML; let pattern = new RegExp(text, "gi"); @@ -121,6 +123,14 @@ function wrapText(text, context, wrapper = 'mark') { c = c.replaceAll(matchStr, `${open}${matchStr}${close}`); context.innerHTML = c; }); + + const images = elems('img', context); + + if(images) { + images.forEach(image => { + image.src = image.src.replaceAll(open, '').replaceAll(close, '').replaceAll(escapedOpen, '').replaceAll(escapedClose, ''); + }); + } } }