diff options
-rw-r--r-- | src/formatter/model.rs | 1 | ||||
-rw-r--r-- | src/formatter/string_formatter.rs | 24 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/formatter/model.rs b/src/formatter/model.rs index 291bf80be..2db307750 100644 --- a/src/formatter/model.rs +++ b/src/formatter/model.rs @@ -91,6 +91,7 @@ impl<'a> StyleVariableHolder<Cow<'a, str>> for Vec<FormatElement<'a>> { self.iter().fold(BTreeSet::new(), |mut acc, el| match el { FormatElement::TextGroup(textgroup) => { acc.extend(textgroup.style.get_style_variables()); + acc.extend(textgroup.format.get_style_variables()); acc } FormatElement::Conditional(format) => { diff --git a/src/formatter/string_formatter.rs b/src/formatter/string_formatter.rs index 229407d34..249048949 100644 --- a/src/formatter/string_formatter.rs +++ b/src/formatter/string_formatter.rs @@ -570,6 +570,30 @@ mod tests { } #[test] + fn test_style_variable_nested() { + const STYLE_VAR_NAME: &str = "style"; + + let format_string = format!("[[text](${STYLE_VAR_NAME})](blue)"); + let inner_style = Some(Color::Red.bold()); + + let formatter = StringFormatter::new(&format_string) + .unwrap() + .map_style(|variable| match variable { + STYLE_VAR_NAME => Some(Ok("red bold".to_owned())), + _ => None, + }); + + assert_eq!( + BTreeSet::from([STYLE_VAR_NAME.into()]), + formatter.get_style_variables() + ); + + let result = formatter.parse(None, None).unwrap(); + let mut result_iter = result.iter(); + match_next!(result_iter, "text", inner_style); + } + + #[test] fn test_styled_variable_as_text() { const FORMAT_STR: &str = "[$var](red bold)"; let var_style = Some(Color::Red.bold()); |