From 445b80bd4f0b0b6e26082f9562bbc822b08ae9e8 Mon Sep 17 00:00:00 2001 From: Aevann Date: Tue, 7 Mar 2023 03:52:02 +0200 Subject: [PATCH] render all images in markdown preview --- files/assets/js/markdown.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/files/assets/js/markdown.js b/files/assets/js/markdown.js index 12d168944..15813cb44 100644 --- a/files/assets/js/markdown.js +++ b/files/assets/js/markdown.js @@ -29,6 +29,11 @@ marked.use({ const reDisableBeforeUnload = /^\/submit|^\/h\/[a-zA-Z0-9_\-]{3,20}\/submit/; +const image_regex_extensions = document.getElementById('IMAGE_FORMATS').value.replaceAll(',', '|') +const regex_pattern = String.raw`(^|\s)(https:\/\/[\w\-.#&/=\?@%;+,:]{5,250}(\.|\?format=)(` + image_regex_extensions + String.raw`)((\?|&)[\w\-.#&/=\?@%;+,:]*)?)($|\s)` +console.log(regex_pattern) +const compiled_regex = new RegExp(regex_pattern, "g"); + function markdown(t) { let input = t.value; @@ -90,6 +95,8 @@ function markdown(t) { } } + input = input.replace(compiled_regex, '$1\n\n![]($2)\n\n') + input = marked(input) const preview = document.getElementById(t.dataset.preview)