diff --git a/front/src/composables/useMarkdown.ts b/front/src/composables/useMarkdown.ts index b4e05a616..f1ab9e7ab 100644 --- a/front/src/composables/useMarkdown.ts +++ b/front/src/composables/useMarkdown.ts @@ -9,6 +9,7 @@ showdown.extension('openExternalInNewTab', { regex: //g, replace (text: string) { const matches = text.match(/href="(.+)">/) ?? [] + const url = matches[1] ?? './' if ((!url.startsWith('http://') && !url.startsWith('https://')) || url.startsWith('mailto:')) { @@ -16,7 +17,7 @@ showdown.extension('openExternalInNewTab', { } const { hostname } = new URL(url) - return hostname !== location.hostname + return hostname !== location.hostname && typeof matches[0] === 'string' ? text.replace(matches[0], `href="${url}" target="_blank" rel="noopener noreferrer">`) : text }