提交 ca5220ec 编写于 作者: D DCloud_LXH

fix: markdown normalizeLink

上级 0214da28
......@@ -46,11 +46,15 @@ function parseBar(tab, file, options) {
}
}
link = path.join('/', link.replace(/\.md\b/, '')
.replace(/\bREADME\b/, '')
.replace(/\/index/, '/')
.replace(/\?id=/, '#'))
.replace(/\\/g, '/')
link = path.join(
'/',
link
.replace(/(\bREADME\.md\b)|(\bREADME(?!\.))/i, 'index.html') // README.md | README | readme.md | readme -> index.html
.replace(/(\bindex\.md\b)|(index(?!\.))/, 'index.html') // /index -> /index.html
.replace(/\.md\b/, '.html') // *.md -> *.html
.replace(/\?id=/, '#') // ?id= -> #
.replace(/\\/g, '/') // \ -> /
)
links.push(link)
}
......
......@@ -16,17 +16,17 @@ function normalizeLink(url) {
}
module.exports = function (md) {
md.normalizeLink = (function (oldNormalizeLink) {
return function (url) {
url = isExternal(url)
? url
: normalizeLink(url)
.replace(/\.md\b/, '.html')
.replace(/\bREADME\b/, 'index.html')
.replace(/\/index(?!\.)/, 'index.html')
.replace(/\?id=/, '#')
.replace(/\\/g, '/')
return oldNormalizeLink.bind(this)(url)
}
})(md.normalizeLink)
md.normalizeLink = (function (oldNormalizeLink) {
return function (url) {
url = isExternal(url)
? url
: normalizeLink(url)
.replace(/(\bREADME\.md\b)|(\bREADME(?!\.))/i, 'index.html') // README.md | README | readme.md | readme -> index.html
.replace(/(\bindex\.md\b)|(index(?!\.))/, 'index.html') // /index -> /index.html
.replace(/\.md\b/, '.html') // *.md -> *.html
.replace(/\?id=/, '#') // ?id= -> #
.replace(/\\/g, '/') // \ -> /
return oldNormalizeLink.bind(this)(url)
}
})(md.normalizeLink)
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册