Available on crate feature
typed only.Expand description
Typed HTML nodes.
Examples
use html_node::typed::{self, elements::*};
// ^^^^^^^^^^^
// required to bring type definitions
// of all basic html elements into
// the current scope.
// (can also use `elements::div`, etc.)
// defines a custom element named `CustomElement`, with the specified attributes.
// underscores in attributes get converted to and from hyphens in the
// `typed::html!` macro and rendering.
// note that global attributes like `id` will be pre-defined when
// using the `typed::element!` macro.
#[derive(Clone, Debug)]
struct Location {
x: i32,
y: i32,
}
impl std::fmt::Display for Location {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{},{}", self.x, self.y)
}
}
typed::element! {
CustomElement("custom-element") {
custom_attr, // implictly typed as a `String`
location: Location,
}
}
// creates a normal `Node`, but checks types at compile-time!
let html = typed::html! {
<div id="container">
<CustomElement id="el" custom-attr="test" location=Location { x: 1, y: 2 } />
</div>
};
assert_eq!(
html.to_string(),
r#"<div id="container"><custom-element id="el" custom-attr="test" location="1,2"></custom-element></div>"#,
);Modules
- Predefined HTML elements.
Macros
- Make a typed set of HTML attributes.
- Make a typed element.
- Make many typed elements.
- Make a typed HTML node.
Traits
- A typed set of HTML attributes.
- A typed HTML element.