diff --git a/browser/components/MarkdownPreview.js b/browser/components/MarkdownPreview.js index 4be33c51..bb663c5e 100755 --- a/browser/components/MarkdownPreview.js +++ b/browser/components/MarkdownPreview.js @@ -1015,16 +1015,19 @@ export default class MarkdownPreview extends React.Component { e.preventDefault() e.stopPropagation() - const href = e.target.getAttribute('href') - const linkHash = href.split('/').pop() + const rawHref = e.target.getAttribute('href') + const parser = document.createElement('a') + parser.href = e.target.getAttribute('href') + const { href, hash } = parser + const linkHash = hash === '' ? rawHref : hash // needed because we're having special link formats that are removed by parser e.g. :line:10 - if (!href) return + if (!rawHref) return // not checked href because parser will create file://... string for [empty link]() - const regexNoteInternalLink = process.env.NODE_ENV === 'production' ? /main.production.html#(.+)/ : /main.development.html#(.+)/ + const regexNoteInternalLink = /.*[main.\w]*.html#/ - if (regexNoteInternalLink.test(linkHash)) { - const targetId = mdurl.encode(linkHash.match(regexNoteInternalLink)[1]) - const targetElement = this.refs.root.contentWindow.document.getElementById( + if (regexNoteInternalLink.test(href)) { + const targetId = mdurl.encode(linkHash) + const targetElement = this.refs.root.contentWindow.document.querySelector( targetId )