A Rust library crate for parsing, manipulating and serializing CSS stylesheets. Makes use of existing CSS parser logic from Servo. Includes forks of code from Servo because these are unpublished on https://crates.io. One use of this library is to minify CSS, as the serialized form it produces is minimal. Another use is provide a crate that others can use for auto-prefixing CSS and to eliminate unused CSS. The values of property declarations are currently stored as a string. Parsing property declarations is a monster job (in effect there are bespoke rules for every property). If you feel like helping...
extern crate css; use ::css::Stylesheet; let some_css = "margin-left: 10pt; top: 20px;".to_owned(); let stylesheet = Stylesheet::parse(&some_css).expect("CSS was invalid"); // Alternatively, load from a file using Stylesheet::from_file_path("/path/to/stylesheet.css").unwrap(); let mut destination = String::new(); // Don't write source-map and source-url comments if any are present in the stylesheet let include_source_urls = false; stylesheet.to_css(&mut destination, include_source_urls).expect("Failed to write to destination"); assert_eq!(&destination, "margin-left:10pt;top:20px"); // To serialize to a Vec<u8> of bytes instead let mut bytes = stylesheet.to_bytes(); // To serialize to a file instead stylesheet.to_file_path("/path/to/to/stylesheet.css").unwrap();
extern crate css; use ::css::parse_selector; let selector = parse_selector("P.myclass").unwrap();
html5ever_ext crate. (The function
domain::selectors::matches() can do matching but needs a lot of HTML logic to do so).
Contains definitions of objects used in Stylesheet.
Temporary fork of CSS selectors as the version we need is not yet available in https://crates.io.
Temporary fork of Servo Arc as the version we need to support CSS selectors is not yet available in https://crates.io.
Represents an entire CSS stylesheet. The values of property declarations are currently stored as a string. Parsing property declarations is a monster job. If you feel like helping...
Represents all the things that can go wrong when parsing.
Represents all the things that can go wrong when loading and saving stylesheets.
Parses a CSS selector