updates to markdown processing to allow custom elements

This commit is contained in:
2023-05-11 18:02:40 -07:00
parent 44315b324a
commit 3ddde81e1c
5 changed files with 43 additions and 32 deletions

View File

@@ -2,13 +2,12 @@
import { JSDOM } from 'jsdom';
import createDOMPurify = require('dompurify');
export function sanitize_html(html: string) : string {
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: {
tagNameCheck: (tag_name) => tag_name === 'svg-icon',
attributeNameCheck: (attr_name) => attr_name === 'icon',
}
CUSTOM_ELEMENT_HANDLING: custom_elements
});
}