6 releases
Uses new Rust 2024
0.3.0 | Apr 6, 2025 |
---|---|
0.2.1 | Apr 5, 2025 |
0.1.2 | Apr 5, 2025 |
#2248 in Algorithms
513 downloads per month
18KB
398 lines
Simple HTML builder
With an Html builder, elements can be created using methods with a matching
name, such as a, body, div, or table. These methods return an Elem,
which borrows from the Html
, and can be closed with the end method.
VoidElem elements, like img and input, do not need to be closed.
Text content can be added using the text or text_len methods, which will automatically escape characters as needed. For content which has already been escaped, use the raw method.
After creating all elements, use String::from(html)
to get the HTML.
All open tags will be closed automatically.
use hatmil::Html;
let mut html = Html::new();
html.div().id("a_div").text("Hello").end();
html.button().class("rounded").text("Press Me!");
let html = String::from(html);
assert_eq!(
html,
"<div id=\"a_div\">Hello</div><button class=\"rounded\">Press Me!</button>"
);