diff --git a/src/node/markdown/plugins/link.ts b/src/node/markdown/plugins/link.ts index d1448bc803e..e88e425ccae 100644 --- a/src/node/markdown/plugins/link.ts +++ b/src/node/markdown/plugins/link.ts @@ -33,7 +33,9 @@ export const linkPlugin = ( // internal anchor links !url.startsWith('#') && // mail links - !url.startsWith('mailto:') + !url.startsWith('mailto:') && + // links to files (other than html/md) + !/\.(?!html|md)\w+($|\?)/i.test(url) ) { normalizeHref(hrefAttr) } @@ -56,7 +58,7 @@ export const linkPlugin = ( const [, path, hash] = indexMatch url = path + hash } else { - let cleanUrl = url.replace(/\#.*$/, '').replace(/\?.*$/, '') + let cleanUrl = url.replace(/[?#].*$/, '') // .md -> .html if (cleanUrl.endsWith('.md')) { cleanUrl = cleanUrl.replace(/\.md$/, '.html') diff --git a/src/node/markdownToVue.ts b/src/node/markdownToVue.ts index 29db746129a..22b9eb38f37 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -107,6 +107,8 @@ export function createMarkdownToVueRenderFn( if (data.links) { const dir = path.dirname(file) for (let url of data.links) { + if (/\.(?!html|md)\w+($|\?)/i.test(url)) continue + if (url.replace(EXTERNAL_URL_RE, '').startsWith('//localhost:')) { recordDeadLink(url) continue