panache_parser/parser/blocks/
blockquotes.rs1use crate::syntax::SyntaxKind;
6use rowan::GreenNodeBuilder;
7
8use crate::parser::utils::container_stack::{Container, ContainerStack};
9
10pub(crate) use crate::parser::utils::marker_utils::{
11 count_blockquote_markers, try_parse_blockquote_marker,
12};
13
14pub(in crate::parser) fn can_start_blockquote(pos: usize, lines: &[&str]) -> bool {
17 if pos == 0 {
19 return true;
20 }
21 if pos > 0 && lines[pos - 1].trim().is_empty() {
23 return true;
24 }
25 false
28}
29
30pub(in crate::parser) fn current_blockquote_depth(containers: &ContainerStack) -> usize {
32 containers
33 .stack
34 .iter()
35 .filter(|c| matches!(c, Container::BlockQuote { .. }))
36 .count()
37}
38
39pub(in crate::parser) fn strip_n_blockquote_markers(line: &str, n: usize) -> &str {
41 let mut remaining = line;
42 for _ in 0..n {
43 if let Some((_, content_start)) = try_parse_blockquote_marker(remaining) {
44 remaining = &remaining[content_start..];
45 } else {
46 break;
47 }
48 }
49 remaining
50}
51
52pub(in crate::parser) fn emit_one_blockquote_marker(
54 builder: &mut GreenNodeBuilder<'static>,
55 leading_spaces: usize,
56 has_trailing_space: bool,
57) {
58 if leading_spaces > 0 {
59 builder.token(SyntaxKind::WHITESPACE.into(), &" ".repeat(leading_spaces));
60 }
61 builder.token(SyntaxKind::BLOCK_QUOTE_MARKER.into(), ">");
62 if has_trailing_space {
63 builder.token(SyntaxKind::WHITESPACE.into(), " ");
64 }
65}