Skip to content

Commit 34d1542

Browse files
authored
fix: don't add .html to urls of non-html files (#515)
fix #265
1 parent 804954c commit 34d1542

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/node/markdown/plugins/link.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ export const linkPlugin = (
3333
// internal anchor links
3434
!url.startsWith('#') &&
3535
// mail links
36-
!url.startsWith('mailto:')
36+
!url.startsWith('mailto:') &&
37+
// links to files (other than html/md)
38+
!/\.(?!html|md)\w+($|\?)/i.test(url)
3739
) {
3840
normalizeHref(hrefAttr)
3941
}
@@ -56,7 +58,7 @@ export const linkPlugin = (
5658
const [, path, hash] = indexMatch
5759
url = path + hash
5860
} else {
59-
let cleanUrl = url.replace(/\#.*$/, '').replace(/\?.*$/, '')
61+
let cleanUrl = url.replace(/[?#].*$/, '')
6062
// .md -> .html
6163
if (cleanUrl.endsWith('.md')) {
6264
cleanUrl = cleanUrl.replace(/\.md$/, '.html')

src/node/markdownToVue.ts

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ export function createMarkdownToVueRenderFn(
107107
if (data.links) {
108108
const dir = path.dirname(file)
109109
for (let url of data.links) {
110+
if (/\.(?!html|md)\w+($|\?)/i.test(url)) continue
111+
110112
if (url.replace(EXTERNAL_URL_RE, '').startsWith('//localhost:')) {
111113
recordDeadLink(url)
112114
continue

0 commit comments

Comments
 (0)