Skip to main content

Crate html_safe_md

Crate html_safe_md 

Source
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.