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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
pub struct ConfigurationSource<'a> {
pub category_namespaces: &'a [&'a str],
pub extension_tags: &'a [&'a str],
pub file_namespaces: &'a [&'a str],
pub link_trail: &'a str,
pub magic_words: &'a [&'a str],
pub protocols: &'a [&'a str],
pub redirect_magic_words: &'a [&'a str],
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum Namespace {
Category,
File,
}
impl crate::Configuration {
#[must_use]
pub fn new(source: &ConfigurationSource) -> Self {
let mut configuration = crate::Configuration {
character_entities: crate::Trie::new(),
link_trail_character_set: crate::HashSet::new(),
magic_words: crate::Trie::new(),
namespaces: crate::Trie::new(),
protocols: crate::Trie::new(),
redirect_magic_words: crate::Trie::new(),
tag_name_map: crate::HashMap::new(),
};
for (name, character) in crate::html_entities::HTML_ENTITIES {
configuration
.character_entities
.add_case_sensitive_term(&format!("{};", name), *character);
}
for character in source.link_trail.chars() {
configuration.link_trail_character_set.insert(character);
}
for protocol in source.protocols {
configuration.protocols.add_term(protocol, ());
}
for magic_word in source.magic_words {
configuration.magic_words.add_term(magic_word, ());
}
for namespace in source.category_namespaces {
configuration
.namespaces
.add_term(&format!("{}:", namespace), Namespace::Category);
}
for namespace in source.file_namespaces {
configuration
.namespaces
.add_term(&format!("{}:", namespace), Namespace::File);
}
for redirect_magic_word in source.redirect_magic_words {
configuration
.redirect_magic_words
.add_term(redirect_magic_word, ());
}
for tag_name in source.extension_tags {
configuration
.tag_name_map
.insert(tag_name.to_string(), crate::TagClass::ExtensionTag);
}
for tag_name in [
"abbr",
"b",
"bdi",
"bdo",
"blockquote",
"br",
"caption",
"center",
"cite",
"code",
"data",
"dd",
"del",
"dfn",
"div",
"dl",
"dt",
"em",
"font",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"hr",
"i",
"ins",
"kbd",
"li",
"mark",
"ol",
"p",
"pre",
"q",
"rb",
"rp",
"rt",
"ruby",
"s",
"samp",
"small",
"span",
"strike",
"strong",
"sub",
"sup",
"table",
"td",
"th",
"time",
"tr",
"tt",
"u",
"ul",
"var",
"wbr",
]
.iter()
{
configuration
.tag_name_map
.insert(tag_name.to_string(), crate::TagClass::Tag);
}
configuration
}
#[must_use]
pub fn parse<'a>(&self, wiki_text: &'a str) -> crate::Output<'a> {
crate::parse::parse(self, wiki_text)
}
}
impl Default for crate::Configuration {
fn default() -> Self {
crate::default::create_configuration()
}
}