Skip to content

Commit 604c83a

Browse files
committed
Fix link issues by pre-processing text by splitting links before processing markdown symbols
1 parent 003ace6 commit 604c83a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/utils/formatString.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,34 @@ function compileToJSON(str) {
7171
let min_index_of = -1
7272
let min_index_of_key = null
7373

74+
let links = linkify.find(str)
75+
let min_index_from_link = false
76+
77+
if(links.length > 0) {
78+
min_index_of = str.indexOf(links[0].value)
79+
min_index_from_link = true
80+
}
81+
7482
Object.keys(pseudo_markdown).forEach(starting_value => {
7583
const io = str.indexOf(starting_value)
7684
if (io >= 0 && (min_index_of < 0 || io < min_index_of)) {
7785
min_index_of = io
7886
min_index_of_key = starting_value
87+
min_index_from_link = false
88+
7989
}
8090
})
8191

92+
if(min_index_from_link && min_index_of_key != -1) {
93+
let str_left = str.substr(0, min_index_of)
94+
let str_link = str.substr(min_index_of, links[0].value.length)
95+
let str_right = str.substr(min_index_of + links[0].value.length)
96+
result.push(str_left)
97+
result.push(str_link)
98+
result = result.concat(compileToJSON(str_right))
99+
return result
100+
}
101+
82102
if (min_index_of_key) {
83103
let str_left = str.substr(0, min_index_of)
84104
const char = min_index_of_key

0 commit comments

Comments
 (0)