diff --git a/files/assets/js/markdown.js b/files/assets/js/markdown.js index 12d168944a..15813cb449 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)