1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// This file is part of html5ever_ext. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/html5ever_ext/master/COPYRIGHT. No part of html5ever_ext, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
// Copyright © 2017 The developers of html5ever_ext. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/html5ever_ext/master/COPYRIGHT.


#![warn(missing_docs)]


//! # html5_ext
//!
//! This is a set of unofficial extensions to the [html5ever](https://github.com/servo/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.
//!


pub extern crate css;
pub extern crate either;
#[macro_use] pub extern crate html5ever;
#[macro_use] extern crate quick_error;


pub use ::css::parse_css_selector;
use ::css::domain::atRules::namespace::NamespaceUrl;
use ::css::domain::selectors::matches;
use ::css::domain::selectors::OurSelector;
use ::css::domain::selectors::OurSelectorImpl;
use ::css::selectors::Element;
use ::css::selectors::OpaqueElement;
use ::css::selectors::SelectorImpl;
use ::css::selectors::attr::AttrSelectorOperation;
use ::css::selectors::attr::CaseSensitivity;
use ::css::selectors::attr::NamespaceConstraint;
use ::css::selectors::attr::SELECTOR_WHITESPACE;
use ::css::selectors::matching::ElementSelectorFlags;
use ::css::selectors::matching::LocalMatchingContext;
use ::css::selectors::matching::MatchingContext;
use ::css::selectors::matching::RelevantLinkStatus;
use ::either::Either;
use ::either::Either::*;
pub use ::html5ever::Attribute;
pub use ::html5ever::LocalName;
pub use ::html5ever::Parser;
use ::html5ever::driver::parse_document;
use ::html5ever::driver::ParseOpts;
pub use ::html5ever::interface::QualName;
pub use ::html5ever::interface::AppendNode;
pub use ::html5ever::interface::AppendText;
pub use ::html5ever::rcdom::Node;
pub use ::html5ever::rcdom::NodeData;
use ::html5ever::rcdom::NodeData::*;
pub use ::html5ever::rcdom::RcDom;
use ::html5ever::tendril::NonAtomic;
pub use ::html5ever::tendril::StrTendril;
use ::html5ever::tendril::Tendril;
use ::html5ever::tendril::TendrilSink;
use ::html5ever::tendril::fmt::UTF8;
use ::html5ever::tendril::stream::Utf8LossyDecoder;
use ::html5ever::tokenizer::TokenizerOpts;
use ::html5ever::tree_builder::ElementFlags;
use ::html5ever::tree_builder::QuirksMode;
use ::html5ever::tree_builder::TreeBuilderOpts;
pub use ::html5ever::tree_builder::TreeSink;
use ::quick_error::ResultExt;
use ::std::cell::Cell;
use ::std::cell::RefCell;
use ::std::fmt;
use ::std::fmt::Debug;
use ::std::fmt::Formatter;
use ::std::io;
use ::std::io::Write;
use ::std::mem::uninitialized;
use ::std::ops::Deref;
use ::std::path::Path;
use ::std::path::PathBuf;
use ::std::rc::Rc;


#[cfg(test)] mod tests;


include!("AriaRole.rs");
include!("AttributeExt.rs");
include!("Dir.rs");
include!("Draggable.rs");
include!("Selectable.rs");
include!("ElementNode.rs");
include!("HtmlError.rs");
include!("is_inter_element_whitespace.rs");
include!("is_space_character.rs");
include!("LocalNameExt.rs");
include!("Minify.rs");
include!("NodeExt.rs");
include!("QualNameExt.rs");
include!("QualNameOnlyExt.rs");
include!("RcDomExt.rs");
include!("UltraMinifyingHtmlSerializer.rs");
include!("UnattachedNode.rs");
include!("UnattachedNodeExt.rs");