Skip to main content

parse_stylesheet_deep

Function parse_stylesheet_deep 

Source
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, to any depth: 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.

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 ");