From e1ef0204f476e03d4a830e2ccb558330f64af2b5 Mon Sep 17 00:00:00 2001 From: Luca Pezzolla Date: Thu, 23 Nov 2023 12:14:25 +0100 Subject: [PATCH] fix: prevent url linking when already wrapped into an anchor tag --- src/utils/html.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/html.ts b/src/utils/html.ts index 39eab4f5..d844b23d 100644 --- a/src/utils/html.ts +++ b/src/utils/html.ts @@ -13,7 +13,7 @@ export const getHtmlTextContent = (text: string) => { export const linkUrls = (html: string) => { const regex = - /(?:https?:\/\/|www\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])/gi; + /(?!]*>[^<])(?:https?:\/\/|www\.)(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*(?:\([-A-Z0-9+&@#/%=~_|$?!:,.]*\)|[A-Z0-9+&@#/%=~_|$])(?![^<]*<\/a>)/gi; return html.replace(regex, match => { if (!match.startsWith('http')) match = `https://${match}`; return `${match}`;