text

Macro text 

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

A convenience macro to construct a rewriting handler for fragments of text in the inner content of an element that can be matched by the specified CSS selector. Beware: this is tricky to use.

The text chunks may split the text nodes into smaller fragments. See TextChunk for more info.

§Example

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

let html = rewrite_str(
    r#"<span>Hello</span>"#,
    RewriteStrSettings {
        element_content_handlers: vec![
            text!("span", |t| {
                if t.last_in_text_node() {
                    t.after(" world", ContentType::Text);
                }

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

assert_eq!(html, r#"<span>Hello world</span>"#);

This macro can create either sendable or non-sendable handlers, but not both in a generic context. H: HandlerTypes bound won’t work with this macro.