| Crates.io | htmlproc |
| lib.rs | htmlproc |
| version | 0.3.3 |
| created_at | 2024-06-12 22:13:27.959274+00 |
| updated_at | 2025-03-16 03:01:37.345246+00 |
| description | HTML processors as utils written in Rust |
| homepage | |
| repository | https://github.com/nabbisen/htmlproc-rs |
| max_upload_size | |
| id | 1270006 |
| size | 54,240 |
HTML processors as utils written in Rust.
Each function is offered as a single feature, so the dependencies are kept small. (omit_enclosure which is used as document outline formatter is exception.)
# install crate
cargo add htmlproc
# install crate with specific features
cargo add htmlproc --features path_to_url
# uninstall
# cargo remove htmlproc
Remove specific tag attribute(s) from HTML text.
First, run cargo add htmlproc --features omit_attr. Then specify attrs to omit. Three formats are available:
attr: remove all attrs from all tags.*.attr: same to the above.tag.attr: remove all attrs from specifig tag. ex) span.styleuse htmlproc::omit_attr::manipulate;
let html = "<div id=\"preserved\"><span style=\"want: remove;\" class=\"also: wanted;\" z-index=\"1\">Content</span></div>";
let omit_attrs = &["style", "*.class", "span.z-index"];
let result: String = manipulate(html, omit_attrs);
Remove specific tag enclosure(s) from HTML text.
use htmlproc::omit_enclosure::manipulate;
let result: String = manipulate("<div>...<span>---</span>...</div>", &["span"]);
Convert paths to URLs.
use htmlproc::path_to_url::{convert, ConvertOptions};
let result: String = convert("<a href=\"/some/path\">link</a>", ConvertOptions::new("target.domain"));
In this case, href value "/some/path" is converted to "https://target.domain/some/path". Options such as http protocol, port number and current directory are available.