File size: 545 Bytes
57aa51e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | import DOMPurify from 'isomorphic-dompurify';
const ALLOWED_TAGS = [
'p',
'br',
'strong',
'u',
'a',
'ul',
'li',
'h1',
'h2',
'h3',
'span',
];
const ALLOWED_ATTR = [
'href',
'target',
'rel',
'class',
'data-mention-id',
'data-mention-label',
];
export const sanitizePostContent = (value: unknown): string => {
if (typeof value !== 'string' || !value) {
return '';
}
return DOMPurify.sanitize(value, {
ALLOWED_TAGS,
ALLOWED_ATTR,
ALLOWED_URI_REGEXP: /^(?:https?:|mailto:|\/|#)/i,
});
};
|