Expand description
§Markdown Walker
A markdown walker trait for traversing markdown AST made by the Comrak crate.
§Example
use std::{cell::RefCell, io};
use comrak::{arena_tree::Node, nodes::{Ast, NodeLink}};
use markdown_walker::MarkdownWalker;
#[derive(Debug, Default, PartialEq)]
struct ImageCount(usize);
impl MarkdownWalker for ImageCount {
fn visit_image<'arena>(
&mut self,
_node: &'arena Node<'arena, RefCell<Ast>>,
_link: &NodeLink,
) -> io::Result<()> {
self.0 += 1;
Ok(())
}
}
#[test]
fn test_image_count() {
let markdown = r#"



"#;
let image_count = ImageCount::from_markdown(markdown).unwrap();
assert_eq!(image_count, ImageCount(3));
}
Traits§
- Markdown
Walker - The main trait we export from this crate. This gives you the ability to build your own types from a given markdown AST made by the Comrak crate. The trait has a default implementation for every one of its methods, so you can choose to override only the methods you need for your type.