Skip to content

Commit

Permalink
Add target=_blank for links
Browse files Browse the repository at this point in the history
  • Loading branch information
smrtrfszm committed Apr 1, 2024
1 parent 1fa7541 commit 5baecdf
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/utils/sanitize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
})
Expand Down

0 comments on commit 5baecdf

Please sign in to comment.