Expand description
Async wrapper for
cloudflare/lol-html.
Since lol-html 2.x, [lol_html::HtmlRewriter] supports Send
via the [lol_html::send] types. This crate wraps it in an
[AsyncRead] implementation, feeding input from an inner async reader
and producing rewritten HTML output.
use lol_async::html::{element, html_content::ContentType, send::Settings};
let mut reader = lol_async::rewrite(
Cursor::new(r#"<html>
<head><title>hello lol</title></head>
<body><h1>hey there</h1></body>
</html>"#),
Settings {
element_content_handlers: vec![element!("h1", |el| {
el.append("<span>this was inserted</span>", ContentType::Html);
Ok(())
})],
..Settings::new_send()
}
);
let mut buf = String::new();
reader.read_to_string(&mut buf).await?;
assert_eq!(buf, r#"<html>
<head><title>hello lol</title></head>
<body><h1>hey there<span>this was inserted</span></h1></body>
</html>"#);Re-exports§
pub use lol_html as html;
Structs§
- Rewriter
- An [
AsyncRead] adapter that streams rewritten HTML.
Functions§
Type Aliases§
- Settings
SettingsforSendableHtmlRewriters.