diff --git a/src/core/components/providers/markdown.jsx b/src/core/components/providers/markdown.jsx index 73f835cf..51ba1c1b 100644 --- a/src/core/components/providers/markdown.jsx +++ b/src/core/components/providers/markdown.jsx @@ -5,16 +5,18 @@ import { linkify } from "remarkable/linkify" import DomPurify from "dompurify" import cx from "classnames" -DomPurify.addHook("beforeSanitizeElements", function (current, ) { - // Attach safe `rel` values to all elements that contain an `href`, - // i.e. all anchors that are links. - // We _could_ just look for elements that have a non-self target, - // but applying it more broadly shouldn't hurt anything, and is safer. - if (current.href) { - current.setAttribute("rel", "noopener noreferrer") - } - return current -}) +if (DomPurify.addHook) { + DomPurify.addHook("beforeSanitizeElements", function (current, ) { + // Attach safe `rel` values to all elements that contain an `href`, + // i.e. all anchors that are links. + // We _could_ just look for elements that have a non-self target, + // but applying it more broadly shouldn't hurt anything, and is safer. + if (current.href) { + current.setAttribute("rel", "noopener noreferrer") + } + return current + }) +} function Markdown({ source, className = "", getConfigs }) { if (typeof source !== "string") {