From a2e04ff18ad27be4dc1c66079941baaec79e003f Mon Sep 17 00:00:00 2001 From: JJ Date: Wed, 4 Jan 2023 15:57:41 -0800 Subject: Copy the last version of the parse_wiki_text crate in for development --- parse_wiki_text/src/bold_italic.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 parse_wiki_text/src/bold_italic.rs (limited to 'parse_wiki_text/src/bold_italic.rs') diff --git a/parse_wiki_text/src/bold_italic.rs b/parse_wiki_text/src/bold_italic.rs new file mode 100644 index 0000000..e5ac613 --- /dev/null +++ b/parse_wiki_text/src/bold_italic.rs @@ -0,0 +1,33 @@ +// Copyright 2019 Fredrik Portström +// This is free software distributed under the terms specified in +// the file LICENSE at the top-level directory of this distribution. + +pub fn parse_bold_italic(state: &mut crate::State) { + let scan_position = state.scan_position; + state.flush(scan_position); + let start_position = state.scan_position; + state.scan_position += 2; + while state.get_byte(state.scan_position) == Some(b'\'') { + state.scan_position += 1; + } + let length = state.scan_position - start_position; + if length < 3 { + state.flushed_position = state.scan_position; + state.nodes.push(crate::Node::Italic { + end: state.flushed_position, + start: start_position, + }); + } else if length < 5 { + state.flushed_position = start_position + 3; + state.nodes.push(crate::Node::Bold { + end: state.flushed_position, + start: start_position, + }); + } else { + state.flushed_position = start_position + 5; + state.nodes.push(crate::Node::BoldItalic { + end: state.flushed_position, + start: start_position, + }); + } +} -- cgit v1.2.3-70-g09d2