Skip to content

Commit

Permalink
fix: prevent url linking when already wrapped into an anchor tag
Browse files Browse the repository at this point in the history
  • Loading branch information
lpezzolla authored and Bri74 committed Nov 23, 2023
1 parent 94927ee commit e1ef020
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
/(?!<a[^>]*>[^<])(?: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 `<a href="${match}">${match}</a>`;
Expand Down

0 comments on commit e1ef020

Please sign in to comment.