add content

This commit is contained in:
2025-05-19 14:14:07 +08:00
parent 6386c3f1b3
commit c2f263ae82
3 changed files with 60 additions and 0 deletions
@@ -0,0 +1,23 @@
import sanitizeHtml from 'sanitize-html';
import { deepMerge } from '@/modules/core/helpers';
export class SanitizeService {
protected config: sanitizeHtml.IOptions = {};
constructor() {
this.config = {
allowedTags: sanitizeHtml.defaults.allowedTags.concat(['img', 'code']),
allowedAttributes: {
...sanitizeHtml.defaults.allowedAttributes,
'*': ['class', 'style', 'height', 'width'],
},
parser: {
lowerCaseTags: true,
},
};
}
sanitize(body: string, options: sanitizeHtml.IOptions = {}) {
return sanitizeHtml(body, deepMerge(this.config, options ?? {}, 'replace'));
}
}