diff --git a/ui/artalk/src/lib/marked-renderer.ts b/ui/artalk/src/lib/marked-renderer.ts index 10be4c99..f00bcfe5 100644 --- a/ui/artalk/src/lib/marked-renderer.ts +++ b/ui/artalk/src/lib/marked-renderer.ts @@ -8,18 +8,25 @@ export function getRenderer() { return renderer } -export const markedLinkRenderer = +const markedLinkRenderer = (renderer: any, orgLinkRenderer: Function) => (href: string, title: string, text: string): string => { - const localLink = href?.startsWith(`${window.location.protocol}//${window.location.hostname}`) + const getLinkOrigin = (link: string) => { + try { + return new URL(link).origin + } catch { + return '' + } + } + const isSameOriginLink = getLinkOrigin(href) === window.location.origin const html = orgLinkRenderer.call(renderer, href, title, text) return html.replace( /^ (block: string, lang: string | undefined): string => { // Colorize the block only if the language is known to highlight.js