use crate::config::Config;
use crate::syntax::SyntaxKind;
use rowan::GreenNodeBuilder;
use crate::parser::utils::container_stack::{Container, ContainerStack};
use crate::parser::utils::text_buffer::ParagraphBuffer;
pub(in crate::parser) fn start_paragraph_if_needed(
containers: &mut ContainerStack,
builder: &mut GreenNodeBuilder<'static>,
) {
if !matches!(containers.last(), Some(Container::Paragraph { .. })) {
builder.start_node(SyntaxKind::PARAGRAPH.into());
containers.push(Container::Paragraph {
buffer: ParagraphBuffer::new(),
});
}
}
pub(in crate::parser) fn append_paragraph_line(
containers: &mut ContainerStack,
_builder: &mut GreenNodeBuilder<'static>,
line: &str,
_config: &Config,
) {
if let Some(Container::Paragraph { buffer }) = containers.stack.last_mut() {
buffer.push_text(line);
}
}
pub(in crate::parser) fn append_paragraph_marker(
containers: &mut ContainerStack,
leading_spaces: usize,
has_trailing_space: bool,
) {
if let Some(Container::Paragraph { buffer }) = containers.stack.last_mut() {
buffer.push_marker(leading_spaces, has_trailing_space);
}
}
pub(in crate::parser) fn current_content_col(containers: &ContainerStack) -> usize {
containers
.stack
.iter()
.rev()
.find_map(|c| match c {
Container::ListItem { content_col, .. } => Some(*content_col),
Container::FootnoteDefinition { content_col, .. } => Some(*content_col),
_ => None,
})
.unwrap_or(0)
}