privatus_analytics/askama.rs
1//! askama support: [`SafeHtml`] and [`Tag`] are not escaped by askama.
2//!
3//! ```
4//! use askama::Template;
5//! use privatus_analytics::{click_attr, event_attrs, props, Config, SafeHtml};
6//!
7//! #[derive(Template)]
8//! #[template(
9//! source = "<head>{{ tag }}</head><button {{ export }}>Export</button><a {{ cta }}>Plans</a>",
10//! ext = "html"
11//! )]
12//! struct Page {
13//! tag: SafeHtml,
14//! export: SafeHtml,
15//! cta: SafeHtml,
16//! }
17//!
18//! let config = Config::new().site_id("pa_YOURSITEID").enabled(true);
19//! let page = Page {
20//! tag: config.tag().to_html(),
21//! export: event_attrs("Report exported", props! { "format" => "csv" }),
22//! cta: click_attr("pricing.cta"),
23//! };
24//! let html = page.render().unwrap();
25//! assert!(html.contains(r#"<button data-privatus-event="Report exported" data-privatus-prop-format="csv">"#));
26//! ```
27//!
28//! askama says it may still escape a marked type in rare cases. If you ever
29//! see `<script` in your page, add the `|safe` filter: `{{ tag|safe }}`.
30
31use crate::html::SafeHtml;
32use crate::tag::Tag;
33
34impl askama::filters::HtmlSafe for SafeHtml {}
35impl askama::filters::HtmlSafe for Tag<'_> {}