postio / libraries /helpers /src /utils /sanitize.post.content.ts
Leon4gr45's picture
Upload folder using huggingface_hub (part 9)
57aa51e verified
Raw
History Blame Contribute Delete
545 Bytes
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,
});
};