Skip to content

Commit

Permalink
Merge pull request #11 from James-LG/james/clone
Browse files Browse the repository at this point in the history
feat: Add clone to HtmlDocument and Xpath
  • Loading branch information
James-LG authored Aug 28, 2022
2 parents 20b9108 + f8c19ad commit 3967080
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "skyscraper"
version = "0.3.1"
version = "0.4.0"
authors = ["James La Novara-Gsell <[email protected]>"]
edition = "2018"
description = "XPath for HTML web scraping"
Expand Down
4 changes: 3 additions & 1 deletion src/html/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub use crate::html::parse::parse;
type TagAttributes = HashMap<String, String>;

/// An HTML tag and its attributes.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub struct HtmlTag {
/// Name of the tag.
pub name: String,
Expand Down Expand Up @@ -111,6 +111,7 @@ impl HtmlTag {
}

/// An HTML node can be either a tag or raw text.
#[derive(Clone)]
pub enum HtmlNode {
/// An HTML tag.
Tag(HtmlTag),
Expand Down Expand Up @@ -199,6 +200,7 @@ impl HtmlNode {
/// HTML document tree represented by an indextree arena and a root node.
///
/// Documents must have a single root node to be valid.
#[derive(Clone)]
pub struct HtmlDocument {
arena: Arena<HtmlNode>,
/// The root node of the document.
Expand Down
9 changes: 5 additions & 4 deletions src/xpath/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ pub use crate::xpath::parse::parse;
/// ^^^^^^^^^^^^^ ^^^^^^^^^^^
/// Predicate 1 Predicate 2
/// ```
#[derive(Debug, PartialEq, Default)]
#[derive(Debug, PartialEq, Default, Clone)]
pub struct XpathQuery {
/// The list of conditions.
pub predicates: Vec<XpathPredicate>,
}

/// A single condition for an XPath search.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum XpathPredicate {
/// Asserts that an attribute has a value greater than the given `value`.
///
Expand Down Expand Up @@ -161,7 +161,7 @@ impl Default for XpathAxes {
}

/// A type of node to search for.
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Clone)]
pub enum XpathSearchNodeType {
/// Search for a tag with the given name.
Element(String),
Expand All @@ -182,7 +182,7 @@ impl Default for XpathSearchNodeType {
/// ^-------------------^----
/// Search Item 1 Search item 2
/// ```
#[derive(Debug, PartialEq, Default)]
#[derive(Debug, PartialEq, Default, Clone)]
pub struct XpathSearchItem {
/// The axis to search on.
pub axis: XpathAxes,
Expand Down Expand Up @@ -218,6 +218,7 @@ pub struct XpathSearchItem {
/// # Ok(())
/// # }
/// ```
#[derive(Clone)]
pub struct Xpath {
items: Vec<XpathSearchItem>,
}
Expand Down

0 comments on commit 3967080

Please sign in to comment.