Expand description
§html-safe-md
Convert untrusted HTML into safe, readable markdown.
Built for email but useful anywhere you need to render HTML from an untrusted source without a webview, remote fetches, or JavaScript execution.
§Pipeline
untrusted HTML → ammonia (allowlist sanitizer) → html2md (markdown conversion) → safe string§Quick Start
// Sanitize HTML to markdown with default email-tuned config
let md = html_safe_md::sanitize_html("<p>Hello <strong>world</strong></p>");
assert!(md.contains("**world**"));
// Render an email body (prefers plain text, falls back to sanitized HTML)
let md = html_safe_md::render_email(
Some("Hey, just following up on our conversation from yesterday.\n\nLet me know."),
Some("<p>HTML version</p>"),
);
assert!(md.contains("following up"));Structs§
- Config
- Configuration for the sanitizer.
Functions§
- is_
junk_ plain - Returns true if the plain-text part looks like a stub or tracking junk rather than real email content.
- render_
email - Render an email body as markdown, preferring plain text when available.
- render_
email_ plain - Render an email body as plain text (no markdown formatting).
- render_
email_ with - Render an email body as markdown with a custom config.
- sanitize_
html - Sanitize untrusted HTML and convert to markdown using the default config.
- sanitize_
html_ with - Sanitize untrusted HTML and convert to markdown with a custom config.