Something went wrong. Try again.
I will pick a better name later.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132import sanitizeHtml from "sanitize-html";
export function sanitizeArticleHtml(html: string) { return sanitizeHtml(html, { allowedTags: sanitizeHtml.defaults.allowedTags.concat([ "img", "figure", "figcaption", "picture", "source", "h1", "h2", "h3", "h4", "pre", "code", ]), allowedAttributes: { a: ["href", "name", "target", "rel"], img: ["src", "srcset", "alt", "title", "width", "height", "loading"], source: ["src", "srcset", "type", "media"], code: ["class"], pre: ["class"], }, allowedSchemes: ["http", "https", "mailto"], transformTags: { a: sanitizeHtml.simpleTransform("a", { rel: "noreferrer", target: "_blank" }), img: sanitizeHtml.simpleTransform("img", { loading: "lazy" }), }, });}