Skip to content

Commit

Permalink
fix: handle links with encoded hash
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Apr 18, 2018
1 parent 4480568 commit f0a1a00
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/markdown/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = md => {
const link = token.attrs[hrefIndex]
const href = link[1]
const isExternal = /^https?:/.test(href)
const isSourceLink = /(\/|\.md|\.html)(#[\w-]*)?$/.test(href)
const isSourceLink = /(\/|\.md|\.html)(#.*)?$/.test(href)
if (isExternal) {
addAttr(token, 'target', '_blank')
addAttr(token, 'rel', 'noopener noreferrer')
Expand All @@ -34,12 +34,13 @@ module.exports = md => {

to = to
.replace(/\.md$/, '.html')
.replace(/\.md(#[\w-]*)$/, '.html$1')
.replace(/\.md(#.*)$/, '.html$1')
// normalize links to README/index
if (/^index|readme\.html/i.test(to)) {
to = '/'
}
link[1] = to
// markdown-it encodes the uri
link[1] = decodeURI(to)
return Object.assign({}, token, {
tag: 'router-link'
})
Expand Down

0 comments on commit f0a1a00

Please sign in to comment.