Merge pull request #143 from bojand/master

Properly handle anchor links local within a file. Fix #142
This commit is contained in:
cinwell.li 2017-04-01 10:26:36 +08:00 committed by GitHub
commit aa6d2afce8
2 changed files with 6 additions and 2 deletions

View File

@ -82,7 +82,7 @@ renderer.code = function (code, lang = '') {
renderer.link = function (href, title, text) {
let blank = ''
if (!/:|(\/{2})/.test(href)) {
href = toURL(href)
href = toURL(href, null, currentPath)
} else {
blank = ' target="_blank"'
}

View File

@ -64,13 +64,17 @@ export function parse (path = window.location.href) {
* to URL
* @param {string} path
* @param {object} qs query params
* @param {string} currentRoute optional current route
*/
export function toURL (path, params) {
export function toURL (path, params, currentRoute) {
const local = currentRoute && path[0] === '#'
const route = parse(replaceSlug(path))
route.query = merge({}, route.query, params)
path = route.path + stringifyQuery(route.query)
path = path.replace(/\.md(\?)|\.md$/, '$1')
if (local) path = currentRoute + path
return cleanPath('#/' + path)
}