Skip to content

Commit

Permalink
Fix link issues by pre-processing text by splitting links before proc…
Browse files Browse the repository at this point in the history
…essing markdown symbols
  • Loading branch information
berksaribas committed Oct 1, 2020
1 parent 003ace6 commit 604c83a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/utils/formatString.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 604c83a

Please sign in to comment.