diff --git a/src/node/markdown/plugins/link.ts b/src/node/markdown/plugins/link.ts index e44c043a14d6..964d67876fc6 100644 --- a/src/node/markdown/plugins/link.ts +++ b/src/node/markdown/plugins/link.ts @@ -32,7 +32,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) } @@ -55,7 +57,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 a596e22bfc3d..937a3d83a57f 100644 --- a/src/node/markdownToVue.ts +++ b/src/node/markdownToVue.ts @@ -104,6 +104,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