14 lines
448 B
TypeScript
14 lines
448 B
TypeScript
|
|
import { JSDOM } from 'jsdom';
|
|
import createDOMPurify = require('dompurify');
|
|
|
|
export type CustomElementHandling = createDOMPurify.Config['CUSTOM_ELEMENT_HANDLING'];
|
|
|
|
export function sanitize_html(html: string, custom_elements?: CustomElementHandling) : string {
|
|
const { window } = new JSDOM('');
|
|
const dom_purify = createDOMPurify(window as any as Window);
|
|
return dom_purify.sanitize(html, {
|
|
CUSTOM_ELEMENT_HANDLING: custom_elements,
|
|
});
|
|
}
|