pub fn parse_stylesheet_deep(css: &str) -> Stylesheet<'_, Block<'_>>Expand description
Parse a stylesheet with every rule’s {} block parsed too, as
declarations and nested rules, down to
MAX_NESTING: what
parse_stylesheet and
SimpleBlock::contents on each block
make, in one pass and
about 70% of the time. The errors are all in the
stylesheet’s list, in the order they were found; a rule dropped for
opening deeper than that is an ErrorKind::InvalidRule.
use parsec_css::{Item, Rule};
let sheet = parsec_css::parse_stylesheet_deep("a { color: red; &:hover { color: blue } }");
let Rule::Qualified(rule) = &sheet.rules[0] else { unreachable!() };
assert!(matches!(&rule.block.items[0], Item::Declaration(d) if d.name == "color"));
let Item::Rule(Rule::Qualified(hover)) = &rule.block.items[1] else { unreachable!() };
assert_eq!(parsec_css::to_css(&hover.prelude), "&:hover ");