diff --git a/src/client/theme-default/composables/repo.ts b/src/client/theme-default/composables/repo.ts index fa6c6ab8..5bb2112b 100644 --- a/src/client/theme-default/composables/repo.ts +++ b/src/client/theme-default/composables/repo.ts @@ -1,6 +1,7 @@ import { computed } from 'vue' import { useData } from 'vitepress' import type { DefaultTheme } from '../config' +import { EXTERNAL_URL_RE } from '../../shared' export const platforms = ['GitHub', 'GitLab', 'Bitbucket'].map((platform) => { return [platform, new RegExp(platform, 'i')] as const @@ -26,7 +27,7 @@ export function useRepo() { function getRepoUrl(repo: string): string { // if the full url is not provided, default to GitHub repo - return /^https?:/.test(repo) ? repo : `https://github.com/${repo}` + return EXTERNAL_URL_RE.test(repo) ? repo : `https://github.com/${repo}` } function getRepoText(url: string, text?: string): string { diff --git a/src/node/markdown/plugins/link.ts b/src/node/markdown/plugins/link.ts index 1e0bcbbb..7664f10a 100644 --- a/src/node/markdown/plugins/link.ts +++ b/src/node/markdown/plugins/link.ts @@ -5,6 +5,7 @@ import MarkdownIt from 'markdown-it' import { MarkdownParsedData } from '../markdown' import { URL } from 'url' +import { EXTERNAL_URL_RE } from '../../shared' const indexRE = /(^|.*\/)index.md(#?.*)$/i @@ -18,7 +19,7 @@ export const linkPlugin = ( if (hrefIndex >= 0) { const hrefAttr = token.attrs![hrefIndex] const url = hrefAttr[1] - const isExternal = /^https?:/.test(url) + const isExternal = EXTERNAL_URL_RE.test(url) if (isExternal) { Object.entries(externalAttrs).forEach(([key, val]) => { token.attrSet(key, val)