diff options
author | Titus Wormer <tituswormer@gmail.com> | 2022-07-07 17:21:38 +0200 |
---|---|---|
committer | Titus Wormer <tituswormer@gmail.com> | 2022-07-07 17:36:35 +0200 |
commit | 4806864e5377a5fef937b3fa02542e620c547969 (patch) | |
tree | c91ae2bbd1dc2037f425efd24d62d05e706e3e60 /src/util | |
parent | c2b4402223e53498078fc33dd55aabc0a48cdb56 (diff) | |
download | markdown-rs-4806864e5377a5fef937b3fa02542e620c547969.tar.gz markdown-rs-4806864e5377a5fef937b3fa02542e620c547969.tar.bz2 markdown-rs-4806864e5377a5fef937b3fa02542e620c547969.zip |
Add basic support for block quotes
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/edit_map.rs | 1 | ||||
-rw-r--r-- | src/util/mod.rs | 1 | ||||
-rw-r--r-- | src/util/skip.rs | 44 |
3 files changed, 46 insertions, 0 deletions
diff --git a/src/util/edit_map.rs b/src/util/edit_map.rs index ae627c1..f67a8b9 100644 --- a/src/util/edit_map.rs +++ b/src/util/edit_map.rs @@ -48,6 +48,7 @@ fn shift_links(events: &mut [Event], jumps: &[(usize, isize)]) { /// Make it easy to insert and remove things while being performant and keeping /// links in check. +#[derive(Debug)] pub struct EditMap { /// Whether this map was consumed already. consumed: bool, diff --git a/src/util/mod.rs b/src/util/mod.rs index d1a0e01..ae1add6 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -6,4 +6,5 @@ pub mod edit_map; pub mod encode; pub mod normalize_identifier; pub mod sanitize_uri; +pub mod skip; pub mod span; diff --git a/src/util/skip.rs b/src/util/skip.rs new file mode 100644 index 0000000..2c4198a --- /dev/null +++ b/src/util/skip.rs @@ -0,0 +1,44 @@ +use crate::tokenizer::{Event, TokenType}; + +/// To do. +pub fn opt(events: &[Event], index: usize, token_types: &[TokenType]) -> usize { + skip_opt_with_direction(events, index, token_types, true) +} + +/// To do. +pub fn opt_back(events: &[Event], index: usize, token_types: &[TokenType]) -> usize { + skip_opt_with_direction(events, index, token_types, false) +} + +/// To do. +fn skip_opt_with_direction( + events: &[Event], + index: usize, + token_types: &[TokenType], + forward: bool, +) -> usize { + let mut index = index; + + while index < events.len() { + let current = &events[index].token_type; + + if !token_types.contains(current) { + break; + } + + // assert_eq!(events[index].event_type, EventType::Enter); + index = if forward { index + 1 } else { index - 1 }; + + loop { + if events[index].token_type == *current { + // assert_eq!(events[index].event_type, EventType::Exit); + index = if forward { index + 1 } else { index - 1 }; + break; + } + + index = if forward { index + 1 } else { index - 1 }; + } + } + + index +} |