@viveeditor/sanitize
v1.1.0
Published
Server-side sanitizer that keeps exactly the HTML viveEditor produces and removes everything else.
Maintainers
Readme
@viveeditor/sanitize
Server-side sanitizer that keeps exactly the HTML viveEditor produces and removes everything else.
Part of viveEditor, a free, open-source rich text editor.
Install
npm install @viveeditor/sanitizeUsage
import { sanitizeHtml } from '@viveeditor/sanitize'
const clean = sanitizeHtml(request.body.html, { embeds: true })Keeps exactly the HTML viveEditor produces and removes everything else, using a full HTML5 parser. HTML over maxBytes (2 MB by default) throws TOO_LARGE, hostile structure throws TOO_COMPLEX. Comment anchors (<span data-vive-comment>) are removed unless you pass comments: 'keep', which you want when storing a draft that is edited again, not when publishing. Comment threads are validated with cleanThreads from @viveeditor/ext-comments/threads. Pending suggestions (<ins data-vive-change> and <del data-vive-change>) are published as approved text by default (suggestions: 'reject': insertions removed, deletions kept as plain text); 'accept' applies them and 'keep' keeps them with validated attributes for a stored draft. Paragraph breaks of pending suggestions stay as breaks unless you keep them. The PHP package viveeditor/sanitizer shares the same allowlist and test corpus. See Sanitize on the server.
License
MIT
