Module stylesheet

Source
Expand description

CSS Stylesheet Parser

This module provides parsing and representation for complete CSS stylesheets containing multiple CSS rules. A stylesheet represents the top-level structure that holds all CSS rules like body { margin: 0; } .title { color: red; }.

§Main API

  • Stylesheet::from_string() - Parse a complete stylesheet from a CSS string
  • Stylesheet::new() - Create a new stylesheet programmatically with optional rules
  • Display trait implementation for converting back to CSS string format

§Examples

use css_structs::Stylesheet;
 
// Parse from string
let css = "body { margin: 0; padding: 0; } h1 { color: red; }";
let stylesheet = Stylesheet::from_string(css).unwrap();
assert_eq!(stylesheet.rules.len(), 2);

// Create with existing rules 
let stylesheet = Stylesheet::new(Some(stylesheet.rules.clone()));
println!("{}", stylesheet);

// Create empty stylesheet
let empty = Stylesheet::new(None);
assert!(empty.rules.is_empty());

Structs§

Stylesheet