What This Adds In Cloud Code
- Sanitizes untrusted markup before storage or mailing.
- Converts rich HTML into plain text summaries.
- Encodes unsafe characters to HTML entities.
Quick Start
js
const HTML = require('html');
const safeHtml = HTML.sanitize(request.params.content || '');API
| Function | Params | Returns | Notes |
|---|---|---|---|
strip_html(input) | input: string | string | Strips tags aggressively. |
sanitize(input, options) | input: string, options?: object | string | Sanitizes via Loofah scrub; options currently ignored. |
to_text(input) | input: string | string | Converts HTML to plain text. |
encode(input, options) | input: string | string | Encodes to named HTML entities. |
Practical Example
js
const HTML = require('html');
const messageHtml = HTML.sanitize(request.params.message);
const messageText = HTML.to_text(messageHtml);Failure Modes & Gotchas
sanitizeoptions are accepted but not applied.- Keep original raw content only if you explicitly need audit trails.