Crates.io | css_forge |
lib.rs | css_forge |
version | 0.1.0 |
source | src |
created_at | 2024-08-12 07:00:33.322725 |
updated_at | 2024-08-12 07:00:33.322725 |
description | A robust and efficient CSS parsing library for Rust |
homepage | |
repository | https://github.com/benodiwal/css_forge |
max_upload_size | |
id | 1334027 |
size | 12,700 |
A robust and efficient CSS parsing library for Rust
Selector Parsing
: Parse complex CSS selectors, including class, ID, and attribute selectors.Property Parsing
: Easily parse CSS properties and their values.Value Parsing
: Parse various CSS value types, including colors, lengths, etc.Error Handling
: Gracefully manage parsing errors such as invalid selectors and unexpected tokens.To use css_forge
, add the following to your Cargo.toml:
[dependencies]
css_forge = "0.1.0"
Here's how you can parse a simple CSS snippet using css_forge:
use css_forge::parser::Parser;
use css_forge::css::Stylesheet;
fn main() {
let input = r#"
.container {
width: 100%;
max-width: 1200px;
}
p { color: #333; }
"#.to_string();
let mut parser = Parser::new(input);
match parser.parse() {
Ok(stylesheet) => println!("Parsed Stylesheet: {:?}", stylesheet),
Err(err) => eprintln!("Parsing error: {:?}", err),
}
}
css_forge gracefully handles common errors during parsing:
use css_forge::{parser::Parser, errors::CssParseError};
fn main() {
let input = ".invalid-selector { color: }".to_string();
let mut parser = Parser::new(input);
match parser.parse() {
Err(CssParseError::InvalidSelector) => eprintln!("Error: Invalid CSS selector"),
Err(CssParseError::InvalidValue) => eprintln!("Error: Invalid property value"),
Ok(stylesheet) => println!("Parsed Stylesheet: {:?}", stylesheet),
Err(err) => eprintln!("Other parsing error: {:?}", err),
}
}
Contributions are welcome! Feel free to open issues, submit pull requests, or fork the repository to make improvements.
This library is open-source and available under the MIT LICENSE.
Happy styling with css_forge! 🎨🚀