File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -1015,16 +1015,19 @@ export default class MarkdownPreview extends React.Component {
1015
1015
e . preventDefault ( )
1016
1016
e . stopPropagation ( )
1017
1017
1018
- const href = e . target . getAttribute ( 'href' )
1019
- const linkHash = href . split ( '/' ) . pop ( )
1018
+ const rawHref = e . target . getAttribute ( 'href' )
1019
+ const parser = document . createElement ( 'a' )
1020
+ parser . href = e . target . getAttribute ( 'href' )
1021
+ const { href, hash } = parser
1022
+ const linkHash = hash === '' ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10
1020
1023
1021
- if ( ! href ) return
1024
+ if ( ! rawHref ) return // not checked href because parser will create file://... string for [empty link]()
1022
1025
1023
- const regexNoteInternalLink = process . env . NODE_ENV === 'production' ? / m a i n . p r o d u c t i o n . h t m l # ( . + ) / : / m a i n .d e v e l o p m e n t .h t m l # ( . + ) /
1026
+ const regexNoteInternalLink = / . * [ m a i n . \w ] * .h t m l # /
1024
1027
1025
- if ( regexNoteInternalLink . test ( linkHash ) ) {
1026
- const targetId = mdurl . encode ( linkHash . match ( regexNoteInternalLink ) [ 1 ] )
1027
- const targetElement = this . refs . root . contentWindow . document . getElementById (
1028
+ if ( regexNoteInternalLink . test ( href ) ) {
1029
+ const targetId = mdurl . encode ( linkHash )
1030
+ const targetElement = this . refs . root . contentWindow . document . querySelector (
1028
1031
targetId
1029
1032
)
1030
1033
You can’t perform that action at this time.
0 commit comments