//! HTML parsing into the node arena, via html5ever. Hand-directed integration //! scaffolding (see the crate root doc comment), not generated code. //! //! `TreeSink` methods take `&self`, so the arena being built is behind a `RefCell`. //! Every method here scopes its `borrow`/`borrow_mut` to the call and returns owned //! data (a [`NodeId`] or a cloned [`markup5ever::QualName`]), never a reference //! borrowed from the cell -- that is what lets a plain `RefCell` work at all, since //! nothing here needs a borrow to outlive the method that took it. use std::cell::RefCell; use html5ever::tendril::TendrilSink; use markup5ever::interface::{ElemName, ElementFlags, NodeOrText, QualName, TreeSink}; use markup5ever::{Attribute, Namespace}; use crate::node::{Attr, ElementData, Node, NodeData, NodeId}; use crate::style_data::StyloData; /// Wraps an owned, cloned [`QualName`] so `TreeSink::elem_name` can return it by /// value instead of borrowing from the arena's `RefCell` (see the module doc comment). struct OwnedElemName(QualName); impl std::fmt::Debug for OwnedElemName { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.0.fmt(f) } } impl ElemName for OwnedElemName { fn ns(&self) -> &Namespace { &self.0.ns } fn local_name(&self) -> &markup5ever::LocalName { &self.0.local } } struct Sink { nodes: RefCell>, /// `target` element id -> its template-contents fragment id, per /// `TreeSink::get_template_contents`. Phase 0's corpus never uses `