@@ -1033,17 +1033,21 @@ export default class MarkdownPreview extends React.Component {
1033
1033
e . stopPropagation ( )
1034
1034
1035
1035
const rawHref = e . target . getAttribute ( 'href' )
1036
+ if ( ! rawHref ) return // not checked href because parser will create file://... string for [empty link]()
1037
+
1036
1038
const parser = document . createElement ( 'a' )
1037
- parser . href = e . target . getAttribute ( 'href' )
1039
+ parser . href = rawHref
1040
+ const isStartWithHash = rawHref [ 0 ] === '#'
1038
1041
const { href, hash } = parser
1039
- const linkHash = hash === '' ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10
1040
1042
1041
- if ( ! rawHref ) return // not checked href because parser will create file://... string for [empty link]()
1043
+ const maybeExternalLink = / h t t p s ? : \/ \/ / . test ( rawHref )
1044
+ const linkHash = ( maybeExternalLink || hash === '' ) ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10
1042
1045
1043
- const extractId = / ( m a i n .h t m l ) ? # /
1044
- const regexNoteInternalLink = new RegExp ( `${ extractId . source } (.+)` )
1045
- if ( regexNoteInternalLink . test ( linkHash ) ) {
1046
- const targetId = mdurl . encode ( linkHash . replace ( extractId , '' ) )
1046
+ const extractIdRegex = / f i l e : \/ \/ .* m a i n .? \w * .h t m l # / // file://path/to/main(.development.)html
1047
+ const regexNoteInternalLink = new RegExp ( `${ extractIdRegex . source } (.+)` )
1048
+ if ( isStartWithHash || regexNoteInternalLink . test ( linkHash ) ) {
1049
+ const extractedId = isStartWithHash ? linkHash . slice ( 1 ) : linkHash . replace ( extractIdRegex , '' )
1050
+ const targetId = mdurl . encode ( extractedId )
1047
1051
const targetElement = this . refs . root . contentWindow . document . getElementById (
1048
1052
targetId
1049
1053
)
0 commit comments