Skip to content

Commit

Permalink
fix: sanitizer removing link target (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pantotone authored Jul 10, 2023
1 parent 6955428 commit 77dea3b
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/components/SanitizedHTML/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ type Props = {
};

const SanitizedHTML: React.FC<Props> = ({dirtyHTML}: Props) => {
DOMPurify.addHook("afterSanitizeAttributes", function (node) {
if ("target" in node) {
node.setAttribute("target", "_blank");
node.setAttribute("rel", "noreferrer noopener nofollow");
}
});

const sanitized = DOMPurify.sanitize(dirtyHTML);

return <div dangerouslySetInnerHTML={{__html: sanitized}}/>;
Expand Down

0 comments on commit 77dea3b

Please sign in to comment.