aboutsummaryrefslogtreecommitdiff
path: root/parse_wiki_text/src/bold_italic.rs
diff options
context:
space:
mode:
authorJJ2023-01-04 23:57:41 +0000
committerJJ2023-01-04 23:57:48 +0000
commita2e04ff18ad27be4dc1c66079941baaec79e003f (patch)
tree256201497d3c3ef3dba9031ee985d407b80b95a6 /parse_wiki_text/src/bold_italic.rs
parentbaf2f93b3002c2a0769bbd53f37d845c7717d95b (diff)
Copy the last version of the parse_wiki_text crate in for development
Diffstat (limited to 'parse_wiki_text/src/bold_italic.rs')
-rw-r--r--parse_wiki_text/src/bold_italic.rs33
1 files changed, 33 insertions, 0 deletions
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 <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_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,
+ });
+ }
+}