Skip to content

Commit 791abab

Browse files
AWolf81Rokt33r
authored andcommitted
add gfm with modified regex & improve link text handling
1 parent d829216 commit 791abab

File tree

5 files changed

+357
-153
lines changed

5 files changed

+357
-153
lines changed

extra_scripts/codemirror/addon/hyperlink/hyperlink.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,16 @@
6565
const className = el.className.split(' ')
6666

6767
if (className.indexOf('cm-url') !== -1) {
68-
const match = /^\((.*)\)|\[(.*)\]|(.*)$/.exec(el.textContent)
68+
// multiple cm-url because of search term
69+
const cmUrlSpans = Array.from(
70+
el.parentNode.getElementsByClassName('cm-url')
71+
)
72+
const textContent =
73+
cmUrlSpans.length > 1
74+
? cmUrlSpans.map(span => span.textContent).join('')
75+
: el.textContent
76+
77+
const match = /^\((.*)\)|\[(.*)\]|(.*)$/.exec(textContent)
6978
const url = match[1] || match[2] || match[3]
7079

7180
// `:storage` is the value of the variable `STORAGE_FOLDER_PLACEHOLDER` defined in `browser/main/lib/dataApi/attachmentManagement`
@@ -134,7 +143,16 @@
134143
return
135144
}
136145

137-
const rawHref = e.target.innerText.trim().slice(1, -1) // get link text from markdown text
146+
// Create URL spans array used for special case "search term is hitting a link".
147+
const cmUrlSpans = Array.from(
148+
e.target.parentNode.getElementsByClassName('cm-url')
149+
)
150+
151+
const innerText =
152+
cmUrlSpans.length > 1
153+
? cmUrlSpans.map(span => span.textContent).join('')
154+
: e.target.innerText
155+
const rawHref = innerText.trim().slice(1, -1) // get link text from markdown text
138156

139157
if (!rawHref) return // not checked href because parser will create file://... string for [empty link]()
140158

0 commit comments

Comments
 (0)