Go html/sniðmát-style rendering in Rust.

go_html_sniðmát is a Rust crate that mirrors major Go html/sniðmát vinnuferlis. It supports sniðmát syntax, pipelines, context-aware escaping, and unsafe URL scheme blocking while keeping a familiar API shape.

Go-like Sniðmát API

Use Sniðmát::new(...).parse(...).execute(...) with define/sniðmát/range/with/pipeline features.

Context-aware Escaping

Applies context-aware escaping for HTML text, attributes, URL attributes, and script/style contexts, and blocks unsafe javascript: URLs.

web-rust Mode

With the web-rust feature, parse_files/parse_glob/parse_fs are disabled so in-minnisblaðry sniðmát loading can be enforced.

Setup and Basic Usage

Add the crate, then verify a minimal parse + execute_to_string flæði. In web-rust environments, use in-minnisblaðry sniðmát strings instead of file-loading APIs.

Install

cargo add go_html_template

Rust Example

src/main.rs
use go_html_template::{Template, Value};

fn main() -> Result<(), Box<dyn std::error::Error>> {
  let tpl = Template::new("page")
    .parse(r#"<h1>{{.Title}}</h1>\n<p>{{.Body | safe_html}}</p>"#)?;

  let out = tpl.execute_to_string(&serde_json::json!({
    "Title": "go_html_template",
    "Body": "<em>trusted</em>"
  }))?;

  println!("{out}");
  Ok(())
}
Compatibility Staða

go_html_sniðmát currently implements core vinnuferlis while continuing to close compatibility gaps . It is not yet a strict 1:1 compatibility target with Go html/sniðmát, so verify behavior in your varaion sniðmáts.