aboutsummaryrefslogtreecommitdiff
path: root/parse_wiki_text/src/magic_word.rs
diff options
context:
space:
mode:
Diffstat (limited to 'parse_wiki_text/src/magic_word.rs')
-rw-r--r--parse_wiki_text/src/magic_word.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/parse_wiki_text/src/magic_word.rs b/parse_wiki_text/src/magic_word.rs
new file mode 100644
index 0000000..40cab17
--- /dev/null
+++ b/parse_wiki_text/src/magic_word.rs
@@ -0,0 +1,26 @@
+// 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_magic_word(state: &mut crate::State, configuration: &crate::Configuration) {
+ if let Ok((match_length, _)) = configuration
+ .magic_words
+ .find(&state.wiki_text[state.scan_position + 2..])
+ {
+ let end_position = match_length + state.scan_position + 2;
+ if state.get_byte(end_position) == Some(b'_')
+ && state.get_byte(end_position + 1) == Some(b'_')
+ {
+ let scan_position = state.scan_position;
+ state.flush(scan_position);
+ state.flushed_position = end_position + 2;
+ state.nodes.push(crate::Node::MagicWord {
+ end: state.flushed_position,
+ start: state.scan_position,
+ });
+ state.scan_position = state.flushed_position;
+ return;
+ }
+ }
+ state.scan_position += 1;
+}