blob: ce30f87f026896ac285d2419f9c137fe731caa53 (
plain) (
blame)
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
|
// Copyright 2019 Fredrik Portström <https://portstrom.com>
// This is free software distributed under the terms specified in
// the file LICENSE at the top-level directory of this distribution.
pub fn parse_external_link_end<'a>(
state: &mut crate::State<'a>,
start_position: usize,
nodes: Vec<crate::Node<'a>>,
) {
let scan_position = state.scan_position;
state.flush(scan_position);
state.scan_position += 1;
state.flushed_position = state.scan_position;
let nodes = std::mem::replace(&mut state.nodes, nodes);
state.nodes.push(crate::Node::ExternalLink {
end: state.scan_position,
nodes,
start: start_position,
});
}
pub fn parse_external_link_end_of_line(state: &mut crate::State) {
let end = state.scan_position;
let open_node = state.stack.pop().unwrap();
state.warnings.push(crate::Warning {
end,
message: crate::WarningMessage::InvalidLinkSyntax,
start: open_node.start,
});
state.rewind(open_node.nodes, open_node.start);
}
pub fn parse_external_link_start(state: &mut crate::State, configuration: &crate::Configuration) {
let scheme_start_position = state.scan_position + 1;
match configuration
.protocols
.find(&state.wiki_text[scheme_start_position..])
{
Err(_) => {
state.scan_position = scheme_start_position;
return;
}
Ok(_) => {
state.push_open_node(crate::OpenNodeType::ExternalLink, scheme_start_position);
}
}
}
|