From 19f8c0aafc17624f4435a8a6cc9efde3a5ec9d33 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Thu, 12 Oct 2023 15:32:16 +0200 Subject: [PATCH] [mastodon-client] Improve mfm-to-html handling of links --- packages/backend/src/server/api/mastodon/helpers/mfm.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/backend/src/server/api/mastodon/helpers/mfm.ts b/packages/backend/src/server/api/mastodon/helpers/mfm.ts index 726e8feca..2b4fa2acf 100644 --- a/packages/backend/src/server/api/mastodon/helpers/mfm.ts +++ b/packages/backend/src/server/api/mastodon/helpers/mfm.ts @@ -123,6 +123,8 @@ export class MfmHelpers { link(node) { const a = doc.createElement("a"); + a.setAttribute("rel", "nofollow noopener noreferrer"); + a.setAttribute("target", "_blank"); a.href = node.props.url; appendChildren(node.children, a); return a; @@ -178,8 +180,10 @@ export class MfmHelpers { url(node) { const a = doc.createElement("a"); + a.setAttribute("rel", "nofollow noopener noreferrer"); + a.setAttribute("target", "_blank"); a.href = node.props.url; - a.textContent = node.props.url; + a.textContent = node.props.url.replace(/^https?:\/\//, ''); return a; },