1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use regex::Regex;
use crate::error::transform::HtmlError;
#[derive(Clone, Debug)]
pub enum QueryKind {
Tag(String),
Class(String),
Attr { name: String, value: String },
}
#[derive(Debug)]
pub enum DataLocation {
Text,
Attr(String),
}
#[derive(Debug)]
pub struct Query {
pub kind: QueryKind,
pub ignore: Option<Vec<QueryKind>>,
}
#[derive(Debug)]
pub struct QueryData {
pub query: Vec<Query>,
pub data_location: DataLocation,
pub regex: Option<Regex>,
}
impl QueryData {
pub fn new(
query: Vec<Query>,
data_location: DataLocation,
re: Option<&str>,
) -> Result<Self, HtmlError> {
Ok(Self {
query,
data_location,
regex: match re {
Some(re) => Some(Regex::new(re)?),
None => None,
},
})
}
}
#[derive(Debug)]
pub struct TitleQuery(pub QueryData);
#[derive(Debug)]
pub struct TextQuery {
pub prepend: Option<String>,
pub inner: QueryData,
}
#[derive(Clone, Copy, Debug)]
pub enum IdQueryKind {
String,
Date,
}
#[derive(Debug)]
pub struct IdQuery {
pub kind: IdQueryKind,
pub inner: QueryData,
}
#[derive(Debug)]
pub struct UrlQuery {
pub prepend: Option<String>,
pub inner: QueryData,
}
#[derive(Debug)]
pub struct ImageQuery {
pub optional: bool,
pub url: UrlQuery,
}