lol_html

Macro element

source
macro_rules! element {
    ($selector:expr, $handler:expr) => { ... };
}
Expand description

A convenience macro to construct a rewriting handler for elements that can be matched by the specified CSS selector.

ยงExample

use lol_html::{rewrite_str, element, RewriteStrSettings};
use lol_html::html_content::ContentType;

let html = rewrite_str(
    r#"<span id="foo"></span>"#,
    RewriteStrSettings {
        element_content_handlers: vec![
            element!("#foo", |el| {
                el.set_inner_content("Hello!", ContentType::Text);

                Ok(())
            })
        ],
        ..RewriteStrSettings::new()
    }
).unwrap();

assert_eq!(html, r#"<span id="foo">Hello!</span>"#);