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 scraper requirement from 0.20.0 to 0.21.0 #106

Merged
merged 5 commits into from
Nov 1, 2024
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
10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]]
Expand Down
4 changes: 2 additions & 2 deletions examples/build_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
8 changes: 5 additions & 3 deletions examples/scraper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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();
Expand Down
23 changes: 14 additions & 9 deletions src/emitters/html5ever.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<h1>hello world</h1>";
///
/// // 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<Attribute>,
Expand All @@ -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)
}

Expand Down Expand Up @@ -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 = "<h1>hello world</h1>";
///
/// // 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,
Expand Down
2 changes: 1 addition & 1 deletion tests/html5lib_tree_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading