From d2eaf8d127b3b8773c0d0cf4fc265428c4ee1ddd Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Wed, 3 Jan 2024 12:01:54 +0800 Subject: [PATCH] fix: add-base-to-md.js --- docs/.vuepress/markdown/add-base-to-md.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/.vuepress/markdown/add-base-to-md.js b/docs/.vuepress/markdown/add-base-to-md.js index 23498f43..f6839fd8 100644 --- a/docs/.vuepress/markdown/add-base-to-md.js +++ b/docs/.vuepress/markdown/add-base-to-md.js @@ -3,12 +3,14 @@ module.exports = function (md, { base = '/' }) { md.core.ruler.after('inline', 'add-base-to-md', function (state) { state.tokens.forEach(function (blockToken) { if (blockToken.type === 'inline' && blockToken.content && blockToken.children && blockToken.children.length) { - if (blockToken.content.indexOf('](/') > -1) { + if (blockToken.content.indexOf('](') > -1) { blockToken.children.forEach(function (inlineToken) { if (inlineToken.type === 'link_open' && inlineToken.attrs && inlineToken.attrs.length) { inlineToken.attrs.forEach(function (attr) { - if (attr[0] === 'href' && attr[1].indexOf('/') === 0 && attr[1].indexOf(base) !== 0) { - attr[1] = base + attr[1].slice(1) + if (attr[0] === 'href') { + // /abc/def.md => ${base}/abc/def.md + if (attr[1].indexOf('/') === 0 && attr[1].indexOf(base) !== 0) attr[1] = base + attr[1].slice(1) + if (/^\w/.test(attr[1])) attr[1] = './' + attr[1] } }); } -- GitLab