[librsvg: 4/8] Add support for comma-separated lists of languages
- From: Marge Bot <marge-bot src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 4/8] Add support for comma-separated lists of languages
- Date: Fri, 15 Oct 2021 21:01:05 +0000 (UTC)
commit 5b918a72edd55d927d124159f95c27a8fb0c31b7
Author: Michael Howell <michael notriddle com>
Date: Wed Oct 13 14:58:34 2021 -0700
Add support for comma-separated lists of languages
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/606>
src/css.rs | 27 ++++++++++++++++++---------
src/element.rs | 5 +----
tests/fixtures/reftests/xml-lang-css.svg | 2 +-
3 files changed, 20 insertions(+), 14 deletions(-)
---
diff --git a/src/css.rs b/src/css.rs
index 3c9f1b97..417c1219 100644
--- a/src/css.rs
+++ b/src/css.rs
@@ -224,14 +224,16 @@ impl<'i> selectors::Parser<'i> for RuleParser {
) -> Result<NonTSPseudoClass, cssparser::ParseError<'i, Self::Error>> {
match &*name {
"lang" => {
- let language_tag = {
- let language_tag = arguments.expect_ident_or_string()?.clone();
+ // Comma-separated lists of languages are a Selectors 4 feature,
+ // but a pretty stable one that hasn't changed in a long time.
+ let tags = arguments.parse_comma_separated(|arg| {
+ let language_tag = arg.expect_ident_or_string()?.clone();
LanguageTag::from_str(&language_tag).map_err(|_| {
-
arguments.new_custom_error(selectors::parser::SelectorParseErrorKind::UnsupportedPseudoClassOrElement(language_tag))
- })?
- };
+
arg.new_custom_error(selectors::parser::SelectorParseErrorKind::UnsupportedPseudoClassOrElement(language_tag))
+ })
+ })?;
arguments.expect_exhausted()?;
- Ok(NonTSPseudoClass::Lang(language_tag))
+ Ok(NonTSPseudoClass::Lang(tags))
}
_ => Err(arguments.new_custom_error(
selectors::parser::SelectorParseErrorKind::UnsupportedPseudoClassOrElement(name),
@@ -339,7 +341,7 @@ impl<'i> AtRuleParser<'i> for RuleParser {
pub enum NonTSPseudoClass {
Link,
Visited,
- Lang(LanguageTag),
+ Lang(Vec<LanguageTag>),
}
impl ToCss for NonTSPseudoClass {
@@ -350,7 +352,14 @@ impl ToCss for NonTSPseudoClass {
match self {
NonTSPseudoClass::Link => write!(dest, "link"),
NonTSPseudoClass::Visited => write!(dest, "visited"),
- NonTSPseudoClass::Lang(lang) => write!(dest, "lang(\"{}\")", lang),
+ NonTSPseudoClass::Lang(lang) => write!(
+ dest,
+ "lang(\"{}\")",
+ lang.iter()
+ .map(ToString::to_string)
+ .collect::<Vec<_>>()
+ .join("\",\"")
+ ),
}
}
}
@@ -549,7 +558,7 @@ impl selectors::Element for RsvgElement {
.0
.borrow_element()
.get_language()
- .map_or(false, |e_lang| css_lang.matches(e_lang)),
+ .map_or(false, |e_lang| css_lang.iter().any(|l| l.matches(e_lang))),
}
}
diff --git a/src/element.rs b/src/element.rs
index 78215028..4eb8c1b4 100644
--- a/src/element.rs
+++ b/src/element.rs
@@ -208,10 +208,7 @@ impl<T: SetAttributes + Draw> ElementInner<T> {
self.language = Some(
LanguageTag::from_str(value)
.map_err(|e| {
- ValueErrorKind::parse_error(&format!(
- "invalid language tag: \"{}\"",
- e
- ))
+ ValueErrorKind::parse_error(&format!("invalid language tag: \"{}\"", e))
})
.attribute(attr)?,
);
diff --git a/tests/fixtures/reftests/xml-lang-css.svg b/tests/fixtures/reftests/xml-lang-css.svg
index 67b6c8ee..9267fb42 100644
--- a/tests/fixtures/reftests/xml-lang-css.svg
+++ b/tests/fixtures/reftests/xml-lang-css.svg
@@ -3,7 +3,7 @@
/* Elements should appear in red-green-blue-yellow order.
The :lang(en) should match en-US. It will also match en-GB,
but that gets overridden later. */
- :lang(en) { fill: red }
+ :lang(en, cn) { fill: red }
/* Languages should be inherited from their parent elements. */
:lang(es) { fill: green }
/* Child languages should override the parent ones. */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]