Skip to content

Commit

Permalink
Update scraper requirement from 0.20.0 to 0.21.0 (#106)
Browse files Browse the repository at this point in the history
* Update scraper requirement from 0.20.0 to 0.21.0

Updates the requirements on [scraper](https://github.com/causal-agent/scraper) to permit the latest version.
- [Release notes](https://github.com/causal-agent/scraper/releases)
- [Commits](rust-scraper/scraper@v0.20.0...v0.21.0)

---
updated-dependencies:
- dependency-name: scraper
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

* bump related deps

* fix dependency mess

* fmt

* fix mut

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Markus Unterwaditzer <markus-tarpit+git@unterwaditzer.net>
  • Loading branch information
dependabot[bot] and untitaker authored Nov 1, 2024
1 parent 0871f88 commit 27be6d5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
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

0 comments on commit 27be6d5

Please sign in to comment.