From 367c1a70b73835d94c3d1a1ee0fb09daf7d68899 Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Tue, 29 Oct 2024 11:43:09 -0700 Subject: [PATCH 1/3] update cssparser to v0.28, selectors to v0.23 --- Cargo.toml | 4 +-- src/select.rs | 69 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index ac8a0ed8..d34f9124 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,10 +15,10 @@ edition = "2018" name = "kuchikiki" [dependencies] -cssparser = "0.27" +cssparser = "0.28" matches = "0.1.4" html5ever = "0.25.1" -selectors = "0.22" +selectors = "0.23" indexmap = "2.2.6" [dev-dependencies] diff --git a/src/select.rs b/src/select.rs index 501f1fec..babab672 100644 --- a/src/select.rs +++ b/src/select.rs @@ -21,16 +21,38 @@ static SELECTOR_WHITESPACE: &[char] = &[' ', '\t', '\n', '\r', '\x0C']; #[derive(Debug, Clone)] pub struct KuchikiSelectors; +#[derive(Default, Clone, Eq, PartialEq)] +pub struct CssLocalName(LocalName); + +impl cssparser::ToCss for CssLocalName { + fn to_css(&self, dest: &mut W) -> fmt::Result + where + W: fmt::Write, + { + write!(dest, "{}", self.0) + } +} + +impl<'a> From<&'a str> for CssLocalName { + fn from(value: &'a str) -> Self { + Self(LocalName::from(value)) + } +} + +impl AsRef for CssLocalName { + fn as_ref(&self) -> &str { + self.0.as_ref() + } +} + impl SelectorImpl for KuchikiSelectors { - type AttrValue = String; - type Identifier = LocalName; - type ClassName = LocalName; - type LocalName = LocalName; - type PartName = LocalName; - type NamespacePrefix = LocalName; + type AttrValue = CssLocalName; + type Identifier = CssLocalName; + type LocalName = CssLocalName; + type NamespacePrefix = CssLocalName; type NamespaceUrl = Namespace; type BorrowedNamespaceUrl = Namespace; - type BorrowedLocalName = LocalName; + type BorrowedLocalName = CssLocalName; type NonTSPseudoClass = PseudoClass; type PseudoElement = PseudoElement; @@ -107,10 +129,6 @@ impl NonTSPseudoClass for PseudoClass { PseudoClass::Active | PseudoClass::Hover | PseudoClass::Focus ) } - - fn has_zero_specificity(&self) -> bool { - false - } } impl ToCss for PseudoClass { @@ -206,8 +224,8 @@ impl selectors::Element for NodeDataRef { } #[inline] - fn has_local_name(&self, name: &LocalName) -> bool { - self.name.local == *name + fn has_local_name(&self, name: &CssLocalName) -> bool { + self.name.local == *name.0 } #[inline] fn has_namespace(&self, namespace: &Namespace) -> bool { @@ -215,17 +233,12 @@ impl selectors::Element for NodeDataRef { } #[inline] - fn is_part(&self, _name: &LocalName) -> bool { + fn is_part(&self, _name: &CssLocalName) -> bool { false } #[inline] - fn exported_part(&self, _: &LocalName) -> Option { - None - } - - #[inline] - fn imported_part(&self, _: &LocalName) -> Option { + fn imported_part(&self, _: &CssLocalName) -> Option { None } @@ -254,18 +267,18 @@ impl selectors::Element for NodeDataRef { } #[inline] - fn has_id(&self, id: &LocalName, case_sensitivity: CaseSensitivity) -> bool { + fn has_id(&self, id: &CssLocalName, case_sensitivity: CaseSensitivity) -> bool { self.attributes .borrow() .get(local_name!("id")) .map_or(false, |id_attr| { - case_sensitivity.eq(id.as_bytes(), id_attr.as_bytes()) + case_sensitivity.eq(id.0.as_bytes(), id_attr.as_bytes()) }) } #[inline] - fn has_class(&self, name: &LocalName, case_sensitivity: CaseSensitivity) -> bool { - let name = name.as_bytes(); + fn has_class(&self, name: &CssLocalName, case_sensitivity: CaseSensitivity) -> bool { + let name = name.0.as_bytes(); !name.is_empty() && if let Some(class_attr) = self.attributes.borrow().get(local_name!("class")) { class_attr @@ -280,18 +293,18 @@ impl selectors::Element for NodeDataRef { fn attr_matches( &self, ns: &NamespaceConstraint<&Namespace>, - local_name: &LocalName, - operation: &AttrSelectorOperation<&String>, + local_name: &CssLocalName, + operation: &AttrSelectorOperation<&CssLocalName>, ) -> bool { let attrs = self.attributes.borrow(); match *ns { NamespaceConstraint::Any => attrs .map .iter() - .any(|(name, attr)| name.local == *local_name && operation.eval_str(&attr.value)), + .any(|(name, attr)| name.local == *local_name.0 && operation.eval_str(&attr.value)), NamespaceConstraint::Specific(ns_url) => attrs .map - .get(&ExpandedName::new(ns_url, local_name.clone())) + .get(&ExpandedName::new(ns_url, local_name.0.clone())) .map_or(false, |attr| operation.eval_str(&attr.value)), } } From 65cbb39954623fe607b51a17f1da7cf06091fab0 Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Thu, 31 Oct 2024 14:48:08 -0700 Subject: [PATCH 2/3] remove matches dependency (in rust stdlib since 1.42) --- Cargo.toml | 1 - src/lib.rs | 2 -- 2 files changed, 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d34f9124..595eafa7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ name = "kuchikiki" [dependencies] cssparser = "0.28" -matches = "0.1.4" html5ever = "0.25.1" selectors = "0.23" indexmap = "2.2.6" diff --git a/src/lib.rs b/src/lib.rs index 3e2a62dc..c6156dea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,8 +8,6 @@ Kuchikiki (口利き) is an HTML tree manipulation library for Rust. #[macro_use] extern crate html5ever; -#[macro_use] -extern crate matches; mod attributes; mod cell_extras; From 651facb2bacb9b6580d381e07c831cdaf5246482 Mon Sep 17 00:00:00 2001 From: Anton Lazarev Date: Thu, 31 Oct 2024 14:54:18 -0700 Subject: [PATCH 3/3] v0.8.6 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 595eafa7..6c1c2d53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "kuchikiki" -version = "0.8.5-speedreader" +version = "0.8.6-speedreader" authors = [ "Brave Authors", "Ralph Giles ",