21 lines
747 B
TypeScript
21 lines
747 B
TypeScript
import sanitize from 'sanitize-html';
|
|
|
|
export function sanitizeHtml(html: string): string {
|
|
return sanitize(html, {
|
|
allowedTags: ['h2', 'h3', 'p', 'strong', 'em', 'u', 's', 'ul', 'ol', 'li', 'a', 'img', 'blockquote', 'br', 'hr'],
|
|
allowedAttributes: { a: ['href', 'rel', 'target'], img: ['src', 'alt'] },
|
|
allowedSchemes: ['https', 'http', 'mailto'],
|
|
allowedSchemesAppliedToAttributes: ['href', 'src'],
|
|
allowProtocolRelative: false,
|
|
});
|
|
}
|
|
|
|
export function sanitizeInline(html: string): string {
|
|
return sanitize(html, {
|
|
allowedTags: ['strong', 'em', 'u', 's', 'br', 'a'],
|
|
allowedAttributes: { a: ['href', 'rel', 'target'] },
|
|
allowedSchemes: ['https', 'http', 'mailto'],
|
|
allowProtocolRelative: false,
|
|
});
|
|
}
|