Implement nested formatting

This commit is contained in:
Juno Takano 2026-01-10 01:18:47 -03:00
commit 3837af387a
7 changed files with 78 additions and 57 deletions

View file

@ -46,7 +46,9 @@ pub fn parse(
log!("Block Context: None -> List on {lexeme}");
state.context.block = Block::List;
state.buffers.list.candidate.ordered = lexeme.match_char('+');
return super::list::parse(lexeme, state, tokens, iterator);
return super::list::parse(
lexeme, state, tokens, iterator, config,
);
} else if Paragraph::probe(lexeme) {
log!("Block Context: None -> Paragraph on {lexeme}");
state.context.block = Block::Paragraph;
@ -78,7 +80,7 @@ pub fn parse(
}
},
Block::List => {
return super::list::parse(lexeme, state, tokens, iterator);
return super::list::parse(lexeme, state, tokens, iterator, config);
},
}
false

View file

@ -5,9 +5,11 @@ use crate::{
syntax::content::parser::{
context::Block,
lexeme::Lexeme,
nest,
state::{ListBuffer, State},
token::{Token, item::Item},
},
types::Config,
};
/// Handles open list contexts until a list is fully parsed.
@ -23,6 +25,7 @@ pub fn parse(
state: &mut State,
tokens: &mut Vec<Token>,
iterator: &mut Peekable<Iter<'_, Lexeme>>,
config: &Config,
) -> bool {
let buffer = &mut state.buffers.list;
let candidate = &mut buffer.candidate;
@ -49,6 +52,7 @@ pub fn parse(
}
if item_candidate.depth.is_some() {
// if the current item candidate has a known depth, push it
item_candidate.text = nest(&item_candidate.text, config);
candidate.items.push(item_candidate.clone());
}
// push list candidate, reset state and exit context
@ -60,6 +64,7 @@ pub fn parse(
} else if lexeme.match_char('\n') {
// found end of item, push it and reset state
log!("Accepting item candidate {item_candidate}");
item_candidate.text = nest(&item_candidate.text, config);
candidate.items.push(item_candidate.clone());
*item_candidate = Item::default();
buffer.depth = 0;