//! Rendering helpers: Askama fragment rendering and HTML escaping for raw //! `format!`-built markup. /// Render an Askama fragment to an HTML string, surfacing a render failure as an /// `AppError` (mapped to 500 + an `HX-Error` header by the error responder) instead /// of the silent `.render().unwrap_or_default()` blank swap, which installs an /// empty HTMX fragment with no error signal (ultra-fuzz Run 12 doubledown S-A). Use /// this for HTMX fragment handlers that return `Result`. pub fn render_fragment(template: &impl askama::Template) -> crate::error::Result { template.render().map_err(|e| { tracing::error!(error = ?e, "fragment render failed"); crate::error::AppError::Internal(anyhow::anyhow!("template render failed")) }) } /// Escape HTML special characters, including `'` so the output is safe in /// single-quoted attribute contexts as well as element text. Use whenever a /// value is interpolated into a raw `format!`-built HTML string instead of an /// auto-escaped template. pub fn escape_html(s: &str) -> String { s.replace('&', "&") .replace('<', "<") .replace('>', ">") .replace('"', """) .replace('\'', "'") }