diff options
author | JJ | 2023-01-04 23:57:41 +0000 |
---|---|---|
committer | JJ | 2023-01-04 23:57:48 +0000 |
commit | a2e04ff18ad27be4dc1c66079941baaec79e003f (patch) | |
tree | 256201497d3c3ef3dba9031ee985d407b80b95a6 /parse_wiki_text/src/external_link.rs | |
parent | baf2f93b3002c2a0769bbd53f37d845c7717d95b (diff) |
Copy the last version of the parse_wiki_text crate in for development
Diffstat (limited to 'parse_wiki_text/src/external_link.rs')
-rw-r--r-- | parse_wiki_text/src/external_link.rs | 47 |
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); + } + } +} |