feat(api): Allow more HTML tags in Markdown

This commit is contained in:
Jesse Wierzbinski 2024-05-11 15:27:19 -10:00
parent 4ce5dfeae3
commit b979daa39a
No known key found for this signature in database
3 changed files with 100 additions and 9 deletions

View file

@ -7,6 +7,29 @@ export const sanitizedHtmlStrip = (html: string) => {
});
};
export const sanitizeHtmlInline = async (
html: string,
extraConfig?: IFilterXSSOptions,
) => {
return sanitizeHtml(html, {
whiteList: {
a: ["href", "title", "target", "rel", "class"],
p: ["class"],
b: ["class"],
i: ["class"],
em: ["class"],
strong: ["class"],
del: ["class"],
u: ["class"],
font: ["color", "size", "face", "class"],
strike: ["class"],
mark: ["class"],
small: ["class"],
},
...extraConfig,
});
};
export const sanitizeHtml = async (
html: string,
extraConfig?: IFilterXSSOptions,
@ -28,6 +51,34 @@ export const sanitizeHtml = async (
ol: ["class"],
li: ["class"],
blockquote: ["class"],
h1: ["class"],
h2: ["class"],
h3: ["class"],
h4: ["class"],
h5: ["class"],
h6: ["class"],
img: ["src", "alt", "title", "class"],
font: ["color", "size", "face", "class"],
table: ["class"],
tr: ["class"],
td: ["class"],
th: ["class"],
tbody: ["class"],
thead: ["class"],
tfoot: ["class"],
hr: ["class"],
strike: ["class"],
figcaption: ["class"],
figure: ["class"],
mark: ["class"],
summary: ["class"],
details: ["class"],
caption: ["class"],
small: ["class"],
video: ["class", "src", "controls"],
audio: ["class", "src", "controls"],
source: ["src", "type"],
track: ["src", "label", "kind"],
},
stripIgnoreTag: false,
escapeHtml: (unsafeHtml) =>