#html5ever #html #html5 #minify #minifier

html5ever_ext

This is a set of unofficial extensions to the html5ever crate’s RcDom and Node structs, including a minifying HTML5 serializer and support for CSS matching

21 releases

Uses old Rust 2015

0.21.20 Dec 4, 2017
0.21.19 Dec 4, 2017
0.21.18 Nov 21, 2017

#15 in #minify

Download history 131/week @ 2022-04-26 88/week @ 2022-05-03 320/week @ 2022-05-10 67/week @ 2022-05-17 107/week @ 2022-05-24 192/week @ 2022-05-31 43/week @ 2022-06-07 3/week @ 2022-06-14 5/week @ 2022-06-21 2/week @ 2022-06-28 23/week @ 2022-07-05 45/week @ 2022-07-12 24/week @ 2022-07-19 24/week @ 2022-07-26 26/week @ 2022-08-02 7/week @ 2022-08-09

81 downloads per month
Used in css-purify

MIT license

120KB
3K SLoC

html5ever_ext

This is a set of unofficial extensions to the html5ever crate's RcDom and Node structs, including a minifying HTML5 serializer and support for CSS matching.

See the documentation.

Licensing

The license for this project is MIT.


lib.rs:

html5_ext

This is a set of unofficial extensions to the html5ever crate's RcDom and Node structs, including a minifying HTML5 serializer and support for CSS matching.

It re-exports the css and html5ever crates, and useful DOM types hidden inside the ::html5ever::markup5ever::rcdom module.

How Tos

To load and minify HTML5

extern crate html5_ext;
use ::html5ever_ext::RcDom;
use ::html5ever_ext::RcDomExt;
use ::html5ever_ext::Minify;

let rc_dom = RcDom::from_file_path_verified_and_stripped_of_comments_and_processing_instructions_and_with_a_sane_doc_type("/path/to/document.html").expect("invalid HTML");
rc_dom.minify_to_file_path();

There are additional methods available on Minify to minify to a byte array or a generic Write-implementing writer.

For more control, eg over serializing multiple node graphs, use the struct UltraMinifyingHtmlSerializer directly.

To match CSS selectors

extern crate html5_ext;
use ::html5ever_ext::RcDom;
use ::html5ever_ext::RcDomExt;
use ::html5ever_ext::parse_css_selector;
use ::html5ever_ext::Selectable;
use ::html5ever_ext::Minify;

let rc_dom = RcDom::from_file_path_verified_and_stripped_of_comments_and_processing_instructions_and_with_a_sane_doc_type("/path/to/document.html").expect("invalid HTML");

let selector = parse_css_selector("p.myclass").unwrap();

assert!(!rc_dom.matches(&selector));

rc_dom.find_all_matching_child_nodes_depth_first_including_this_one(&selector, |node|
{
	//Minify is implemented on node.children as well as node and rc_dom.
	eprintln!("{}", node.children.debug_string());

	const SHORTCUT: bool = false;
	SHORTCUT
})

To work with Nodes

Use the NodeExt, Minify, Selectable and QualNameExt traits.

Dependencies

~5MB
~105K SLoC