mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
fix local link detection by creating a link tag to parse the input string
This commit is contained in:
@@ -1015,16 +1015,19 @@ export default class MarkdownPreview extends React.Component {
|
|||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
|
||||||
const href = e.target.getAttribute('href')
|
const rawHref = e.target.getAttribute('href')
|
||||||
const linkHash = href.split('/').pop()
|
const parser = document.createElement('a')
|
||||||
|
parser.href = e.target.getAttribute('href')
|
||||||
|
const { href, hash } = parser
|
||||||
|
const linkHash = hash === '' ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10
|
||||||
|
|
||||||
if (!href) return
|
if (!rawHref) return // not checked href because parser will create file://... string for [empty link]()
|
||||||
|
|
||||||
const regexNoteInternalLink = process.env.NODE_ENV === 'production' ? /main.production.html#(.+)/ : /main.development.html#(.+)/
|
const regexNoteInternalLink = /.*[main.\w]*.html#/
|
||||||
|
|
||||||
if (regexNoteInternalLink.test(linkHash)) {
|
if (regexNoteInternalLink.test(href)) {
|
||||||
const targetId = mdurl.encode(linkHash.match(regexNoteInternalLink)[1])
|
const targetId = mdurl.encode(linkHash)
|
||||||
const targetElement = this.refs.root.contentWindow.document.getElementById(
|
const targetElement = this.refs.root.contentWindow.document.querySelector(
|
||||||
targetId
|
targetId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user