Skip to content

Commit d705a99

Browse files
committed
feat: add pub fn for parsing specified property value
1 parent 384f89f commit d705a99

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

  • float-pigment-css/src/parser

float-pigment-css/src/parser/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,19 @@ pub fn parse_inline_style(
313313
(properties, state.warnings)
314314
}
315315

316+
/// Parse a string of the property value of the specified `property_name`.
317+
pub fn parse_property_value_string(
318+
property_name: &str,
319+
source: &str,
320+
) -> (Vec<PropertyMeta>, Vec<Warning>) {
321+
let mut parser_input = ParserInput::new(source);
322+
let mut parser = Parser::new(&mut parser_input);
323+
let mut properties = vec![];
324+
let mut state: ParseState = ParseState::new(None, StyleParsingDebugMode::None, None);
325+
let _ = parse_property_value(&mut parser, property_name, &mut properties, &mut state, None);
326+
(properties, state.warnings)
327+
}
328+
316329
pub(crate) fn parse_selector_only(source: &str) -> Result<Selector, Warning> {
317330
let mut parser_input = ParserInput::new(source);
318331
let mut parser = Parser::new(&mut parser_input);
@@ -2011,6 +2024,7 @@ fn parse_custom_property_value_with_important<'a, 't: 'a, 'i: 't>(
20112024

20122025
#[cfg(test)]
20132026
mod test {
2027+
use crate::{property::Property, typing::DisplayType};
20142028

20152029
use super::{is_url, parse_color_to_rgba, resolve_relative_path};
20162030

@@ -2110,6 +2124,13 @@ mod test {
21102124
assert!(!is_url("www.wxweb/float-pigment"));
21112125
}
21122126

2127+
#[test]
2128+
fn parse_property_value_string() {
2129+
let (prop_none, warnings) = super::parse_property_value_string("display", "none");
2130+
assert!(warnings.is_empty());
2131+
assert_eq!(prop_none[0].property().unwrap(), Property::Display(DisplayType::None));
2132+
}
2133+
21132134
#[cfg(test)]
21142135
mod parse_inline_style {
21152136
use crate::{

0 commit comments

Comments
 (0)