Expand description
Typed HTML support for Rust.
HTML is not simple. There are many different nodes, attributes,
relationships, and types - and no compiler to help with any of that This
crate provides type-safe bindings to construct HTML elements natively in
Rust. So you don’t have to remember whether <ol>
takes a <li>
, or whether
it’s the other way around.
Examples
We can create HTML structures one-by-one:
use html::text_content::OrderedList;
let tree = OrderedList::builder()
.list_item(|li| li.text("hello").class("pigeon").end())
.list_item(|li| li.text("world").class("pigeon").end())
.build();
let string = tree.to_string();
But we can also use Rust’s native control flow structures such as loops to iterate over items and create HTML:
use html::text_content::OrderedList;
let mut ol = OrderedList::builder();
for name in ["hello", "world"] {
ol.list_item(|li| li.text(name).end());
}
let tree = ol.build();
assert_eq!(tree.to_string(), r#"<ol><li>hello</li><li>world</li></ol>"#);
Modules
- Content sectioning elements
- Demarcating edits elements
- Embedded content elements
- Forms elements
- Inline text elements
- Interactive elements
- Image and multimedia content
- Metadata elements
- Root elements
- Scripting elements
- Table content elements
- Text content elements
- Web Components
Traits
- The Embedded content category
- The Flow content category
- The Heading content category
- An HTML Element
- The Interactive content category
- The Metadata content category
- The Palpable content category
- The Phrasing content category
- The Script-supporting elements content category
- The Sectioning content category
- A text element
- The Transparent content category