Compare plain list item counter.
This commit is contained in:
@@ -44,6 +44,7 @@ use crate::types::IndentationLevel;
|
||||
use crate::types::Object;
|
||||
use crate::types::PlainList;
|
||||
use crate::types::PlainListItem;
|
||||
use crate::types::PlainListItemCounter;
|
||||
use crate::types::PlainListType;
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
@@ -166,8 +167,9 @@ fn plain_list_item<'b, 'g, 'r, 's>(
|
||||
|(_bullet_type, bull)| !Into::<&str>::into(bull).starts_with("*") || indent_level > 0,
|
||||
)(remaining)?;
|
||||
|
||||
let (remaining, _maybe_counter_set) =
|
||||
let (remaining, maybe_counter_set) =
|
||||
opt(tuple((space1, tag("[@"), counter_set_value, tag("]"))))(remaining)?;
|
||||
let maybe_counter_set = maybe_counter_set.map(|(_, _, val, _)| val);
|
||||
|
||||
let (remaining, maybe_checkbox) = opt(tuple((space1, item_checkbox)))(remaining)?;
|
||||
|
||||
@@ -213,6 +215,7 @@ fn plain_list_item<'b, 'g, 'r, 's>(
|
||||
source: source.into(),
|
||||
indentation: indent_level,
|
||||
bullet: bull.into(),
|
||||
counter: maybe_counter_set,
|
||||
checkbox: None,
|
||||
tag: maybe_tag
|
||||
.map(|(_ws, item_tag)| item_tag)
|
||||
@@ -256,6 +259,7 @@ fn plain_list_item<'b, 'g, 'r, 's>(
|
||||
source: source.into(),
|
||||
indentation: indent_level,
|
||||
bullet: bull.into(),
|
||||
counter: maybe_counter_set,
|
||||
checkbox: maybe_checkbox.map(|(_, (checkbox_type, source))| {
|
||||
(checkbox_type, Into::<&str>::into(source))
|
||||
}),
|
||||
@@ -316,12 +320,25 @@ fn counter<'b, 'g, 'r, 's>(
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
fn counter_set_value<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, OrgSource<'s>> {
|
||||
fn counter_set_value<'s>(input: OrgSource<'s>) -> Res<OrgSource<'s>, PlainListItemCounter> {
|
||||
alt((
|
||||
recognize(one_of(
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
|
||||
)),
|
||||
digit1,
|
||||
map(
|
||||
one_of("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),
|
||||
|letter| {
|
||||
let num = match letter {
|
||||
'a'..='z' => (letter as u32) - ('a' as u32) + 1,
|
||||
'A'..='Z' => (letter as u32) - ('A' as u32) + 1,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
PlainListItemCounter::try_from(num)
|
||||
.expect("Counter set value should be between 1 and 26 inclusive.")
|
||||
},
|
||||
),
|
||||
map(digit1, |num: OrgSource<'_>| {
|
||||
Into::<&str>::into(num)
|
||||
.parse()
|
||||
.expect("digit1 must parse to a number.")
|
||||
}),
|
||||
))(input)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user