- Notifications
You must be signed in to change notification settings - Fork0
Low output latency streaming HTML parser/rewriter with CSS selector-based API
License
luminati-io/lol-html
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
LowOutputLatency streamingHTML rewriter/parser with CSS-selector based API.
It is designed to modify HTML on the fly with minimal buffering. It can quickly handle very largedocuments, and operate in environments with limited memory resources. More details can be found in theblog post.
The crate serves as a back-end for the HTML rewriting functionality ofCloudflare Workers, but can be usedas a standalone library with a convenient API for a wide variety of HTML rewriting/analysis tasks.
Rewrite insecure hyperlinks:
use lol_html::{element,HtmlRewriter,Settings};fnmain() ->Result<(),Box<dyn std::error::Error>>{letmut output =vec![];letmut rewriter =HtmlRewriter::new(Settings{element_content_handlers:vec![ element!("a[href]", |el|{let href = el.get_attribute("href").expect("href was required").replace("http:","https:"); el.set_attribute("href",&href)?;Ok(())})], ..Settings::default()}, |c:&[u8]| output.extend_from_slice(c)); rewriter.write(b"<div><a href=")?; rewriter.write(b"http://example.com>")?; rewriter.write(b"</a></div>")?; rewriter.end()?;assert_eq!(String::from_utf8(output)?,r#"<div><a href="https://example.com"></a></div>"#);Ok(())}
BSD licensed. See theLICENSE file for details.
About
Low output latency streaming HTML parser/rewriter with CSS selector-based API
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- Rust86.9%
- C12.8%
- Shell0.3%