@@ -542,21 +542,36 @@ export default class MarkdownPreview extends React.Component {
542
542
return
543
543
}
544
544
545
- const noteHash = e . target . href . split ( '/' ) . pop ( )
545
+ const linkHash = href . split ( '/' ) . pop ( )
546
+
547
+ const regexNoteInternalLink = / m a i n .h t m l # ( .+ ) /
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
+
546
558
// this will match the new uuid v4 hash and the old hash
547
559
// e.g.
548
560
// :note:1c211eb7dcb463de6490 and
549
561
// :note:7dd23275-f2b4-49cb-9e93-3454daf1af9c
550
562
const regexIsNoteLink = / ^ : n o t e : ( [ a - z A - Z 0 - 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
553
566
}
567
+
554
568
// this will match the old link format storage.key-note.key
555
569
// e.g.
556
570
// 877f99c3268608328037-1c211eb7dcb463de6490
557
571
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
560
575
}
561
576
}
562
577
0 commit comments