From f0a1a00cffe3bd8ce8c9a86ce3d17060aead57f6 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 18 Apr 2018 18:22:57 -0400 Subject: [PATCH] fix: handle links with encoded hash --- lib/markdown/link.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/markdown/link.js b/lib/markdown/link.js index 16ad7e5bd0..969fedde75 100644 --- a/lib/markdown/link.js +++ b/lib/markdown/link.js @@ -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') @@ -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' })