mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
optimize implementation for a0c15182
This commit is contained in:
@@ -1040,13 +1040,14 @@ export default class MarkdownPreview extends React.Component {
|
|||||||
const isStartWithHash = rawHref[0] === '#'
|
const isStartWithHash = rawHref[0] === '#'
|
||||||
const { href, hash } = parser
|
const { href, hash } = parser
|
||||||
|
|
||||||
const maybeExternalLink = /https?:\/\//.test(rawHref)
|
const linkHash = hash === '' ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10
|
||||||
const linkHash = (maybeExternalLink || hash === '') ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10
|
|
||||||
|
|
||||||
const extractIdRegex = /file:\/\/.*main.?\w*.html#/ // file://path/to/main(.development.)html
|
const extractIdRegex = /file:\/\/.*main.?\w*.html#/ // file://path/to/main(.development.)html
|
||||||
const regexNoteInternalLink = new RegExp(`${extractIdRegex.source}(.+)`)
|
const regexNoteInternalLink = new RegExp(`${extractIdRegex.source}(.+)`)
|
||||||
if (isStartWithHash || regexNoteInternalLink.test(linkHash)) {
|
if (isStartWithHash || regexNoteInternalLink.test(rawHref)) {
|
||||||
const extractedId = isStartWithHash ? linkHash.slice(1) : linkHash.replace(extractIdRegex, '')
|
const posOfHash = linkHash.indexOf('#')
|
||||||
|
if (posOfHash > -1) {
|
||||||
|
const extractedId = linkHash.slice(posOfHash + 1)
|
||||||
const targetId = mdurl.encode(extractedId)
|
const targetId = mdurl.encode(extractedId)
|
||||||
const targetElement = this.refs.root.contentWindow.document.getElementById(
|
const targetElement = this.refs.root.contentWindow.document.getElementById(
|
||||||
targetId
|
targetId
|
||||||
@@ -1057,6 +1058,7 @@ export default class MarkdownPreview extends React.Component {
|
|||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// this will match the new uuid v4 hash and the old hash
|
// this will match the new uuid v4 hash and the old hash
|
||||||
// e.g.
|
// e.g.
|
||||||
|
|||||||
Reference in New Issue
Block a user