victoria_dom/lib.rs
1#![doc(html_root_url = "https://docs.rs/victoria-dom/0.1.2")]
2#![deny(missing_docs)]
3#![deny(warnings)]
4#![deny(missing_debug_implementations)]
5
6//! Minimalistic HTML parser with CSS selectors
7//!
8//! The project has been inspired by [Mojo::DOM](https://metacpan.org/pod/Mojo::DOM).
9//!
10//! It will even try to interpret broken HTML, so you should not use it for validation.
11//!
12//! # Examples
13//!
14//! ```
15//! extern crate victoria_dom;
16//!
17//! use victoria_dom::DOM;
18//!
19//! fn main() {
20//! let html = r#"<html><div id="main">Hello, <a href="http://rust-lang.org" alt="The Rust Programing Language">Rust</a></div></html>"#;
21//! let dom = DOM::new(html);
22//!
23//! assert_eq!(dom.at("html").unwrap().text_all(), "Hello, Rust");
24//! assert_eq!(dom.at("div#main > a").unwrap().attr("alt").unwrap(), "The Rust Programing Language");
25//! }
26//! ```
27//!
28//! # Supported CSS selectors
29//!
30//! * `*` Any element.
31//! * `E` An element of type `E`.
32//! * `E[foo]` An `E` element with a `foo` attribute.
33//! * `E[foo="bar"]` An `E` element whose `foo` attribute value is exactly equal to `bar`.
34//! * `E[foo~="bar"]` An `E` element whose `foo` attribute value is a list of whitespace-separated values, one of which is exactly equal to `bar`.
35//! * `E[foo^="bar"]` An `E` element whose `foo` attribute value begins exactly with the string `bar`.
36//! * `E[foo$="bar"]` An `E` element whose `foo` attribute value ends exactly with the string `bar`.
37//! * `E[foo*="bar"]` An `E` element whose `foo` attribute value contains the substring `bar`.
38//! * `E:root` An `E` element, root of the document.
39//! * `E:nth-child(n)` An `E` element, the `n-th` child of its parent.
40//! * `E:nth-last-child(n)` An `E` element, the `n-th` child of its parent, counting from the last one.
41//! * `E:nth-of-type(n)` An `E` element, the `n-th` sibling of its type.
42//! * `E:nth-last-of-type(n)` An `E` element, the `n-th` sibling of its type, counting from the last one.
43//! * `E:first-child` An `E` element, first child of its parent.
44//! * `E:last-child` An `E` element, last child of its parent.
45//! * `E:first-of-type` An `E` element, first sibling of its type.
46//! * `E:last-of-type` An `E` element, last sibling of its type.
47//! * `E:only-child` An `E` element, only child of its parent.
48//! * `E:only-of-type` An `E` element, only sibling of its type.
49//! * `E:empty` An `E` element that has no children (including text nodes).
50//! * `E:checked` A user interface element `E` which is checked (for instance a radio-button or checkbox).
51//! * `E.warning` An `E` element whose class is `warning`.
52//! * `E#myid` An `E` element with ID equal to `myid`.
53//! * `E:not(s)` An `E` element that does not match simple selector `s`.
54//! * `E F` An `F` element descendant of an `E` element.
55//! * `E > F` An `F` element child of an `E` element.
56//! * `E + F` An `F` element immediately preceded by an `E` element.
57//! * `E ~ F` An `F` element preceded by an `E` element.
58//! * `E, F, G` Elements of type `E`, `F` and `G`.
59//! * `E[foo=bar][bar=baz]` An `E` element whose attributes match all following attribute selectors.
60
61#[macro_use] extern crate lazy_static;
62#[macro_use] extern crate maplit;
63extern crate regex;
64
65pub use dom::DOM;
66
67mod dom;
68mod util;