pub mod bare;
pub mod terminal;
#[doc(inline)]
pub use bare::parse as summarize;
#[doc(inline)]
pub use terminal::parse;
use log::{trace, warn};
use markdown::mdast::Node;
pub trait Visitor {
fn text(&self) -> String;
fn visit(&mut self, node: &Node);
fn swallow(&mut self, node: &Node)
where
Self: Sized,
{
trace!("swallowing node: {node:#?}");
node.accept_children(self);
}
fn unknown(&self, node: &Node) {
warn!("unhandled node: {node:#?}");
}
}
pub trait Visitable {
fn accept<V: Visitor>(&self, visitor: &mut V);
fn accept_children<V: Visitor>(&self, visitor: &mut V);
}
impl Visitable for Node {
fn accept<V: Visitor>(&self, visitor: &mut V) {
visitor.visit(self);
}
fn accept_children<V: Visitor>(&self, visitor: &mut V) {
if let Some(children) = self.children() {
for child in children {
child.accept(visitor);
}
}
}
}
trait TextAppendable {
fn push_text(&mut self, text: &str);
}
#[cfg(test)]
mod test_utils;