aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-14 17:40:10 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-14 17:40:10 +0200
commit8183323c432fc1359c634feb68bc372e13f0bd03 (patch)
tree0c80086a956d216960cedc436a3b22372190b7a8 /src/util
parente2c9664b0d63ec686f9e4625ac11bb21720f74dc (diff)
downloadmarkdown-rs-8183323c432fc1359c634feb68bc372e13f0bd03.tar.gz
markdown-rs-8183323c432fc1359c634feb68bc372e13f0bd03.tar.bz2
markdown-rs-8183323c432fc1359c634feb68bc372e13f0bd03.zip
Add support for container state
* Fix to parse list item continuation based on how big the initial list item prefix was * Fix list items that start with blank lines
Diffstat (limited to '')
-rw-r--r--src/util/skip.rs18
-rw-r--r--src/util/span.rs4
2 files changed, 15 insertions, 7 deletions
diff --git a/src/util/skip.rs b/src/util/skip.rs
index 10ba364..d2ad914 100644
--- a/src/util/skip.rs
+++ b/src/util/skip.rs
@@ -5,15 +5,23 @@ use crate::tokenizer::{Event, EventType};
/// Skip from `index`, optionally past `token_types`.
pub fn opt(events: &[Event], index: usize, token_types: &[Token]) -> usize {
- skip_opt_with_direction(events, index, token_types, true)
+ skip_opt_impl(events, index, token_types, true)
}
/// Skip from `index`, optionally past `token_types`, backwards.
pub fn opt_back(events: &[Event], index: usize, token_types: &[Token]) -> usize {
- skip_opt_with_direction(events, index, token_types, false)
+ skip_opt_impl(events, index, token_types, false)
}
-pub fn to(events: &[Event], mut index: usize, token_types: &[Token]) -> usize {
+pub fn to_back(events: &[Event], index: usize, token_types: &[Token]) -> usize {
+ to_impl(events, index, token_types, false)
+}
+
+pub fn to(events: &[Event], index: usize, token_types: &[Token]) -> usize {
+ to_impl(events, index, token_types, true)
+}
+
+pub fn to_impl(events: &[Event], mut index: usize, token_types: &[Token], forward: bool) -> usize {
while index < events.len() {
let current = &events[index].token_type;
@@ -21,14 +29,14 @@ pub fn to(events: &[Event], mut index: usize, token_types: &[Token]) -> usize {
break;
}
- index += 1;
+ index = if forward { index + 1 } else { index - 1 };
}
index
}
/// Skip internals.
-fn skip_opt_with_direction(
+fn skip_opt_impl(
events: &[Event],
mut index: usize,
token_types: &[Token],
diff --git a/src/util/span.rs b/src/util/span.rs
index 32dd00f..72b451d 100644
--- a/src/util/span.rs
+++ b/src/util/span.rs
@@ -6,9 +6,9 @@ use crate::util::codes::serialize as serialize_codes;
/// A struct representing the span of an opening and closing event of a token.
#[derive(Debug)]
pub struct Span {
- /// Absolute offset (and `index` in `codes`) of where this span starts.
+ /// Absolute offset (an `index` in `codes`) of where this span starts.
pub start_index: usize,
- /// Absolute offset (and `index` in `codes`) of where this span ends.
+ /// Absolute offset (an `index` in `codes`) of where this span ends.
pub end_index: usize,
}