Macro html_node::typed_html
source · typed_html!() { /* proc-macro */ }
Expand description
The text to Node::Text
macro which checks element/attribute types.
Examples
Passing Type-Checking
use html_node::{html, text, typed_html, typed::elements::div};
let html = typed_html! {
<div class="cool" id="hello-world" data-my-attr="hello" aria-label="world">
{text!("Hello, world!")}
</div>
};
let expected = "\
<div class=\"cool\" id=\"hello-world\" data-my-attr=\"hello\" aria-label=\"world\">\
Hello, world!\
</div>\
";
assert_eq!(html.to_string(), expected);
Failing Type-Checking
ⓘ
use html_node::{html, text, typed_html, typed::elements::div};
// ^^^^^^^^^^^^^^^^^^^^
// must import to get definition of `div` in macros.
// can also `use html_node::typed::elements::*;`
let html = typed_html! {
// ERROR: struct `html_node::typed::elements::DivAttributes` has no field named `my_attr`
<div class="cool" id="hello-world" my-attr="hello">
{text!("Hello, world!")}
</div>
};