Macro html_node::typed::html

source ·
html!() { /* proc-macro */ }
Available on crate feature typed only.
Expand description

Make a typed HTML node.

Examples

Passing Type-Checking

use html_node::typed::{self, elements::*};

let html = typed::html! {
    <div class="cool" id="hello-world" data-my-attr="hello" aria-label="world">
        "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::typed::{self, 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>
};