"""Safe markdown → HTML renderer for curator-authored marketplace content. Two stages: 1. **Render** — `markdown-it-py` in CommonMark mode (no raw HTML pass-through, no autolink to javascript:, no unsafe blocks). Tables and strikethrough are enabled because they show up routinely in `long_description` / `sample_interaction.assistant`. Linkify is OFF — curators write explicit links; auto-linking bare strings adds attack surface without value here. 2. **Sanitize** — funnel the rendered HTML through `nh3` (Rust-backed ammonia allowlist) so anything the renderer let through that we don't want reaching the browser (raw HTML the curator inlined, `javascript:` URLs, on*-handlers, unknown tags) gets stripped. Used by `app/api/marketplace.py` to pre-render `description` and `sample_interaction.assistant` from `marketplace-metadata.json` before the HTML lands in `PluginDetailResponse`. The template injects with `{{ x | safe }}` trusting the stored value — no second-pass sanitization on render. """ from __future__ import annotations from typing import Optional import nh3 from markdown_it import MarkdownIt # CommonMark-strict renderer. `html=False` disables inline raw HTML so a # curator who pastes `