aboutsummaryrefslogtreecommitdiff
path: root/parse_wiki_text/src/external_link.rs
diff options
context:
space:
mode:
Diffstat (limited to 'parse_wiki_text/src/external_link.rs')
-rw-r--r--parse_wiki_text/src/external_link.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/parse_wiki_text/src/external_link.rs b/parse_wiki_text/src/external_link.rs
new file mode 100644
index 0000000..ce30f87
--- /dev/null
+++ b/parse_wiki_text/src/external_link.rs
@@ -0,0 +1,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);
+ }
+ }
+}