Continued work on item parser.
Still needs to: 1. Do context things 2. Fix the double-space after the tag separator issue 3. Add support for indentation 4. Write item_end 5. Write plain_list
This commit is contained in:
parent
5e7c891681
commit
37070689c6
@ -17,6 +17,7 @@ use super::text::space;
|
||||
use super::text::text_element;
|
||||
use super::token::ListItem;
|
||||
use super::token::PlainList;
|
||||
use super::token::Token;
|
||||
use super::Context;
|
||||
|
||||
pub fn plain_list<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, PlainList<'s>> {
|
||||
@ -25,16 +26,33 @@ pub fn plain_list<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str,
|
||||
}
|
||||
|
||||
fn item<'r, 's>(context: Context<'r, 's>, i: &'s str) -> Res<&'s str, ListItem<'s>> {
|
||||
let _ = consumed(tuple((
|
||||
let (remaining, (source, (bul, count, check, tg, sp, (contents, end)))) = consumed(tuple((
|
||||
bullet,
|
||||
opt(tuple((space, counter_set))),
|
||||
opt(tuple((space, check_box))),
|
||||
opt(tuple((space, item_tag))),
|
||||
space,
|
||||
// TODO: This context should probably be something involving the item
|
||||
context_many_till(context, text_element, item_end),
|
||||
)))(i)?;
|
||||
// todo
|
||||
todo!()
|
||||
|
||||
let elements = contents
|
||||
.into_iter()
|
||||
.filter_map(|token| match token {
|
||||
Token::TextElement(text_element) => Some(text_element),
|
||||
Token::Paragraph(_) => panic!("There should only be text elements in items."),
|
||||
})
|
||||
.collect();
|
||||
|
||||
let ret = ListItem {
|
||||
source,
|
||||
bullet: bul,
|
||||
counter_set: count.map(|(_spc, count)| count),
|
||||
check_box: check.map(|(_spc, check)| check),
|
||||
item_tag: tg.map(|(_spc, tg)| tg),
|
||||
contents: elements,
|
||||
};
|
||||
Ok((remaining, ret))
|
||||
}
|
||||
|
||||
fn counter<'s>(i: &'s str) -> Res<&'s str, &'s str> {
|
||||
|
@ -111,9 +111,9 @@ impl<'a> Source<'a> for PlainList<'a> {
|
||||
pub struct ListItem<'a> {
|
||||
pub source: &'a str,
|
||||
pub bullet: &'a str,
|
||||
pub counter_set: &'a str,
|
||||
pub check_box: &'a str,
|
||||
pub item_tag: &'a str,
|
||||
pub counter_set: Option<&'a str>,
|
||||
pub check_box: Option<&'a str>,
|
||||
pub item_tag: Option<&'a str>,
|
||||
pub contents: Vec<TextElement<'a>>,
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user