Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update html5ever and indexmap #76

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "kuchikiki"
version = "0.8.6-speedreader"
version = "0.8.7-speedreader"
authors = [
"Brave Authors",
"Ralph Giles <rgiles@brave.com>",
Expand All @@ -16,9 +16,9 @@ name = "kuchikiki"

[dependencies]
cssparser = "0.28"
html5ever = "0.25.1"
html5ever = "0.29.1"
selectors = "0.23"
indexmap = "2.2.6"
indexmap = "2.6.0"

[dev-dependencies]
tempfile = "3"
37 changes: 19 additions & 18 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct ParseOpts {
pub tree_builder: html5ever::tree_builder::TreeBuilderOpts,

/// A callback for HTML parse errors (which are never fatal).
pub on_parse_error: Option<Box<dyn FnMut(Cow<'static, str>)>>,
pub on_parse_error: Option<Box<dyn Fn(Cow<'static, str>)>>,
}

/// Parse an HTML document with html5ever and the default configuration.
Expand Down Expand Up @@ -65,7 +65,7 @@ pub struct Sink {
pub document_node: NodeRef,

/// The Sink will invoke this callback if it encounters a parse error.
pub on_parse_error: Option<Box<dyn FnMut(Cow<'static, str>)>>,
pub on_parse_error: Option<Box<dyn Fn(Cow<'static, str>)>>,
}

impl Default for Sink {
Expand All @@ -79,6 +79,7 @@ impl Default for Sink {

impl TreeSink for Sink {
type Output = Self;
type ElemName<'a> = ExpandedName<'a>;

fn finish(self) -> Self {
self
Expand All @@ -87,19 +88,19 @@ impl TreeSink for Sink {
type Handle = NodeRef;

#[inline]
fn parse_error(&mut self, message: Cow<'static, str>) {
if let Some(ref mut handler) = self.on_parse_error {
fn parse_error(&self, message: Cow<'static, str>) {
if let Some(ref handler) = self.on_parse_error {
handler(message)
}
}

#[inline]
fn get_document(&mut self) -> NodeRef {
fn get_document(&self) -> NodeRef {
self.document_node.clone()
}

#[inline]
fn set_quirks_mode(&mut self, mode: QuirksMode) {
fn set_quirks_mode(&self, mode: QuirksMode) {
self.document_node
.as_document()
.unwrap()
Expand All @@ -119,7 +120,7 @@ impl TreeSink for Sink {

#[inline]
fn create_element(
&mut self,
&self,
name: QualName,
attrs: Vec<Attribute>,
_flags: ElementFlags,
Expand All @@ -141,17 +142,17 @@ impl TreeSink for Sink {
}

#[inline]
fn create_comment(&mut self, text: StrTendril) -> NodeRef {
fn create_comment(&self, text: StrTendril) -> NodeRef {
NodeRef::new_comment(text)
}

#[inline]
fn create_pi(&mut self, target: StrTendril, data: StrTendril) -> NodeRef {
fn create_pi(&self, target: StrTendril, data: StrTendril) -> NodeRef {
NodeRef::new_processing_instruction(target, data)
}

#[inline]
fn append(&mut self, parent: &NodeRef, child: NodeOrText<NodeRef>) {
fn append(&self, parent: &NodeRef, child: NodeOrText<NodeRef>) {
match child {
NodeOrText::AppendNode(node) => parent.append(node),
NodeOrText::AppendText(text) => {
Expand All @@ -167,7 +168,7 @@ impl TreeSink for Sink {
}

#[inline]
fn append_before_sibling(&mut self, sibling: &NodeRef, child: NodeOrText<NodeRef>) {
fn append_before_sibling(&self, sibling: &NodeRef, child: NodeOrText<NodeRef>) {
match child {
NodeOrText::AppendNode(node) => sibling.insert_before(node),
NodeOrText::AppendText(text) => {
Expand All @@ -184,7 +185,7 @@ impl TreeSink for Sink {

#[inline]
fn append_doctype_to_document(
&mut self,
&self,
name: StrTendril,
public_id: StrTendril,
system_id: StrTendril,
Expand All @@ -194,7 +195,7 @@ impl TreeSink for Sink {
}

#[inline]
fn add_attrs_if_missing(&mut self, target: &NodeRef, attrs: Vec<Attribute>) {
fn add_attrs_if_missing(&self, target: &NodeRef, attrs: Vec<Attribute>) {
let element = target.as_element().unwrap();
let mut attributes = element.attributes.borrow_mut();

Expand All @@ -214,12 +215,12 @@ impl TreeSink for Sink {
}

#[inline]
fn remove_from_parent(&mut self, target: &NodeRef) {
fn remove_from_parent(&self, target: &NodeRef) {
target.detach()
}

#[inline]
fn reparent_children(&mut self, node: &NodeRef, new_parent: &NodeRef) {
fn reparent_children(&self, node: &NodeRef, new_parent: &NodeRef) {
// FIXME: Can this be done more effciently in rctree,
// by moving the whole linked list of children at once?
for child in node.children() {
Expand All @@ -228,12 +229,12 @@ impl TreeSink for Sink {
}

#[inline]
fn mark_script_already_started(&mut self, _node: &NodeRef) {
fn mark_script_already_started(&self, _node: &NodeRef) {
// FIXME: Is this useful outside of a browser?
}

#[inline]
fn get_template_contents(&mut self, target: &NodeRef) -> NodeRef {
fn get_template_contents(&self, target: &NodeRef) -> NodeRef {
target
.as_element()
.unwrap()
Expand All @@ -243,7 +244,7 @@ impl TreeSink for Sink {
}

fn append_based_on_parent_node(
&mut self,
&self,
element: &NodeRef,
prev_element: &NodeRef,
child: NodeOrText<NodeRef>,
Expand Down