From 604c83a600c31f5c2106e43d9db6ffbd259c4b2a Mon Sep 17 00:00:00 2001 From: Berk Emre Saribas Date: Thu, 1 Oct 2020 19:13:12 +0300 Subject: [PATCH] Fix link issues by pre-processing text by splitting links before processing markdown symbols --- src/utils/formatString.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/utils/formatString.js b/src/utils/formatString.js index 3b4d82a8..61e7cea8 100644 --- a/src/utils/formatString.js +++ b/src/utils/formatString.js @@ -71,14 +71,34 @@ function compileToJSON(str) { let min_index_of = -1 let min_index_of_key = null + let links = linkify.find(str) + let min_index_from_link = false + + if(links.length > 0) { + min_index_of = str.indexOf(links[0].value) + min_index_from_link = true + } + Object.keys(pseudo_markdown).forEach(starting_value => { const io = str.indexOf(starting_value) if (io >= 0 && (min_index_of < 0 || io < min_index_of)) { min_index_of = io min_index_of_key = starting_value + min_index_from_link = false + } }) + if(min_index_from_link && min_index_of_key != -1) { + let str_left = str.substr(0, min_index_of) + let str_link = str.substr(min_index_of, links[0].value.length) + let str_right = str.substr(min_index_of + links[0].value.length) + result.push(str_left) + result.push(str_link) + result = result.concat(compileToJSON(str_right)) + return result + } + if (min_index_of_key) { let str_left = str.substr(0, min_index_of) const char = min_index_of_key