From 5baecdfd391d45546c6a70dc70936df012093f90 Mon Sep 17 00:00:00 2001 From: Szepesi Tibor Date: Mon, 1 Apr 2024 03:28:50 +0200 Subject: [PATCH] Add target=_blank for links --- src/utils/sanitize.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/utils/sanitize.ts b/src/utils/sanitize.ts index 483753b..e796042 100644 --- a/src/utils/sanitize.ts +++ b/src/utils/sanitize.ts @@ -30,6 +30,13 @@ function sanitize(purify: DOMPurifyI, parser: DOMParser, dirty: string): string fixURLOrigin(dom) + purify.addHook('afterSanitizeAttributes', function (node) { + if (node.tagName === 'A') { + node.setAttribute('target', '_blank') + node.setAttribute('rel', 'noopener') + } + }) + const clean = purify.sanitize(dom.body, { ADD_TAGS: ['iframe'], })