Crates.io | malva |
lib.rs | malva |
version | |
source | src |
created_at | 2023-09-06 00:48:10.985615 |
updated_at | 2024-12-09 15:01:55.028654 |
description | Configurable, smart and fast CSS, SCSS, Sass and Less formatter. |
homepage | |
repository | https://github.com/g-plane/malva |
max_upload_size | |
id | 964942 |
Cargo.toml error: | TOML parse error at line 19, column 1 | 19 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Malva is a configurable, smart and fast CSS, SCSS, Sass and Less formatter.
You can format source code string by using [format_text
] function.
use malva::{config::FormatOptions, format_text, Syntax};
let options = FormatOptions::default();
assert_eq!("a {
color: red;
}
", &format_text("a{color:red}", Syntax::Css, &options).unwrap());
For detailed documentation of configuration, please refer to Configuration on GitHub.
If there're syntax errors in source code, it will return Err
:
use malva::{config::FormatOptions, format_text, Syntax};
let options = FormatOptions::default();
assert!(format_text("a{", Syntax::Css, &options).is_err());
If you have already parsed the AST with Raffia,
you can use [print_stylesheet
] to print it.
Please note that though you have AST,
you still need to provide comments and specify syntax,
also create [LineBounds
] manually.
use malva::{config::FormatOptions, print_stylesheet, LineBounds, Syntax};
use raffia::{ast::Stylesheet, ParserBuilder};
let input = "a{color:red}";
let mut comments = vec![];
let mut parser = ParserBuilder::new(input)
.syntax(Syntax::Css)
.comments(&mut comments)
.build();
let stylesheet = parser.parse::<Stylesheet>().unwrap();
let options = FormatOptions::default();
let line_bounds = LineBounds::new(input);
assert_eq!("a {
color: red;
}
", &print_stylesheet(&stylesheet, &comments, Some(input), line_bounds, Syntax::Css, &options));