use tracing::{debug, trace};
use super::block::BLOCKQUOTE_RE;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct BlockquotePrefix<'a> {
raw_prefix: &'a str,
depth: usize,
inner: &'a str,
}
impl<'a> BlockquotePrefix<'a> {
#[must_use]
pub fn parse(line: &'a str) -> Option<Self> {
let line_len = line.len();
let Some(captures) = BLOCKQUOTE_RE.captures(line) else {
trace!(
line_len,
reason = "no_blockquote_prefix",
"blockquote prefix rejected"
);
return None;
};
let raw_prefix = captures.get(1)?.as_str();
let inner = captures.get(2)?.as_str();
let depth = raw_prefix.bytes().filter(|byte| *byte == b'>').count();
debug!(
line_len,
prefix_len = raw_prefix.len(),
depth,
inner_len = inner.len(),
"blockquote prefix parsed"
);
Some(Self {
raw_prefix,
depth,
inner,
})
}
#[must_use]
pub fn raw_prefix(&self) -> &'a str { self.raw_prefix }
#[must_use]
pub fn depth(&self) -> usize { self.depth }
#[must_use]
pub fn inner(&self) -> &'a str { self.inner }
}