Skip to content

Commit 30548a6

Browse files
authored
Merge pull request #1868 from yosmoc/1820
fix internal note link bug #1820
2 parents ce052d1 + c9c28ed commit 30548a6

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

browser/components/MarkdownPreview.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,21 +542,36 @@ export default class MarkdownPreview extends React.Component {
542542
return
543543
}
544544

545-
const noteHash = e.target.href.split('/').pop()
545+
const linkHash = href.split('/').pop()
546+
547+
const regexNoteInternalLink = /main.html#(.+)/
548+
if (regexNoteInternalLink.test(linkHash)) {
549+
const targetId = mdurl.encode(linkHash.match(regexNoteInternalLink)[1])
550+
const targetElement = this.refs.root.contentWindow.document.getElementById(targetId)
551+
552+
if (targetElement != null) {
553+
this.getWindow().scrollTo(0, targetElement.offsetTop)
554+
}
555+
return
556+
}
557+
546558
// this will match the new uuid v4 hash and the old hash
547559
// e.g.
548560
// :note:1c211eb7dcb463de6490 and
549561
// :note:7dd23275-f2b4-49cb-9e93-3454daf1af9c
550562
const regexIsNoteLink = /^:note:([a-zA-Z0-9-]{20,36})$/
551-
if (regexIsNoteLink.test(noteHash)) {
552-
eventEmitter.emit('list:jump', noteHash.replace(':note:', ''))
563+
if (regexIsNoteLink.test(linkHash)) {
564+
eventEmitter.emit('list:jump', linkHash.replace(':note:', ''))
565+
return
553566
}
567+
554568
// this will match the old link format storage.key-note.key
555569
// e.g.
556570
// 877f99c3268608328037-1c211eb7dcb463de6490
557571
const regexIsLegacyNoteLink = /^(.{20})-(.{20})$/
558-
if (regexIsLegacyNoteLink.test(noteHash)) {
559-
eventEmitter.emit('list:jump', noteHash.split('-')[1])
572+
if (regexIsLegacyNoteLink.test(linkHash)) {
573+
eventEmitter.emit('list:jump', linkHash.split('-')[1])
574+
return
560575
}
561576
}
562577

0 commit comments

Comments
 (0)