diff --git a/Cargo.toml b/Cargo.toml index b162fdd..ba53d18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,8 +22,9 @@ libtest-mimic = "0.8.1" # https://github.com/bheisler/iai/issues/34 # need to have cache simulation running because of bencher.dev iai = { git = "https://github.com/sigaloid/iai", rev = "d56a597" } +markup5ever_rcdom = "0.5.0-unofficial" # required for examples/scraper.rs -scraper = "0.20.0" +scraper = "0.21.0" argh = "0.1.12" [features] @@ -34,13 +35,10 @@ default = ["jetscii"] # The tree-builder feature contains utilities to use html5ever's DOM and tree # builder with html5gum's tokenizer. -tree-builder = ["html5ever", "markup5ever_rcdom"] +tree-builder = ["html5ever"] [dependencies] -# intentionally held back from 0.29 until scraper updates -html5ever = { version = "0.27.0", optional = true } -markup5ever_rcdom = { version = "0.3.0", optional = true } - +html5ever = { version = "0.29.0", optional = true } jetscii = { version = "0.5.1", optional = true } [[bench]] diff --git a/examples/build_tree.rs b/examples/build_tree.rs index 8314804..411c2db 100644 --- a/examples/build_tree.rs +++ b/examples/build_tree.rs @@ -62,10 +62,10 @@ fn main() { let errors = rcdom.errors; - if !errors.is_empty() { + if !errors.borrow().is_empty() { println!("\nParse errors:"); - for err in errors.iter() { + for err in errors.borrow().iter() { println!(" {}", err); } } diff --git a/examples/scraper.rs b/examples/scraper.rs index 4a60e26..25373b9 100644 --- a/examples/scraper.rs +++ b/examples/scraper.rs @@ -14,8 +14,9 @@ use std::io::{stdin, Read}; use argh::FromArgs; +use html5ever::interface::tree_builder::TreeSink; use html5gum::emitters::html5ever::parse_document; -use scraper::{Html, Selector}; +use scraper::{Html, HtmlTreeSink, Selector}; /// Read some HTML from stdin and parse it according to the given selector. #[derive(FromArgs)] @@ -41,8 +42,9 @@ fn main() { Html::parse_document(&input) } else { let dom = Html::new_document(); - let Ok(dom) = parse_document(&input, dom, Default::default()); - dom + let tree_sink = HtmlTreeSink::new(dom); + let Ok(tree_sink) = parse_document(&input, tree_sink, Default::default()); + tree_sink.finish() }; let selector = Selector::parse(&cli.selector).unwrap(); diff --git a/src/emitters/html5ever.rs b/src/emitters/html5ever.rs index f97aa89..cddb5ed 100644 --- a/src/emitters/html5ever.rs +++ b/src/emitters/html5ever.rs @@ -300,24 +300,26 @@ fn map_tokenizer_state(input: Html5everState) -> State { /// equivalent to the same functions in [html5ever::driver]. /// /// ``` -/// use html5ever::{local_name, QualName, ns, namespace_url}; // extern crate html5ever; -/// use scraper::Html; // extern crate scraper; +/// use html5ever::{local_name, interface::TreeSink, QualName, ns, namespace_url}; // extern crate html5ever; +/// use scraper::{HtmlTreeSink, Html}; // extern crate scraper; /// /// let input = "

hello world

"; /// /// // equivalent to `Html::parse_fragment` /// let dom = Html::new_fragment(); -/// let Ok(dom) = html5gum::emitters::html5ever::parse_fragment( +/// let tree_sink = HtmlTreeSink::new(dom); +/// let Ok(tree_sink) = html5gum::emitters::html5ever::parse_fragment( /// input, -/// dom, +/// tree_sink, /// Default::default(), /// QualName::new(None, ns!(html), local_name!("body")), /// Vec::new() /// ); +/// let dom: Html = tree_sink.finish(); /// ``` pub fn parse_fragment<'a, R, Sink>( input: R, - mut sink: Sink, + sink: Sink, opts: ParseOpts, context_name: QualName, context_attrs: Vec, @@ -326,7 +328,7 @@ where R: Readable<'a>, Sink: TreeSink, { - let context_elem = create_element(&mut sink, context_name, context_attrs); + let context_elem = create_element(&sink, context_name, context_attrs); parse_fragment_for_element(input, sink, opts, context_elem, None) } @@ -363,17 +365,20 @@ where /// equivalent to the same functions in [html5ever::driver]. /// /// ```rust -/// use scraper::Html; // extern crate scraper; +/// use html5ever::interface::TreeSink; // extern crate html5ever; +/// use scraper::{HtmlTreeSink, Html}; // extern crate scraper; /// /// let input = "

hello world

"; /// /// // equivalent to `Html::parse_document` /// let dom = Html::new_document(); -/// let Ok(dom) = html5gum::emitters::html5ever::parse_document( +/// let tree_sink = HtmlTreeSink::new(dom); +/// let Ok(tree_sink) = html5gum::emitters::html5ever::parse_document( /// input, -/// dom, +/// tree_sink, /// Default::default() /// ); +/// let dom: Html = tree_sink.finish(); /// ``` pub fn parse_document<'a, R, Sink>( input: R, diff --git a/tests/html5lib_tree_builder.rs b/tests/html5lib_tree_builder.rs index 5810030..133eea2 100644 --- a/tests/html5lib_tree_builder.rs +++ b/tests/html5lib_tree_builder.rs @@ -163,7 +163,7 @@ fn build_test(testcase: Testcase, fname: &str, i: usize, scripting: bool) -> Tri if let Some(ref frag) = testcase.document_fragment { let frag = frag.trim_end_matches('\n'); let context_name = context_name(frag); - let context_element = create_element(&mut rcdom, context_name, Vec::new()); + let context_element = create_element(&rcdom, context_name, Vec::new()); tree_builder = TreeBuilder::new_for_fragment(rcdom, context_element, None, opts); initial_state = Some(map_tokenizer_state( tree_builder.tokenizer_state_for_context_elem(),