markdown-walker 0.0.1

A markdown walker trait for the comrak crate
Documentation
  • Coverage
  • 100%
    45 out of 45 items documented1 out of 45 items with examples
  • Size
  • Source code size: 46.81 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.18 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 34s Average build duration of successful builds.
  • all releases: 34s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • esmevane

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#"
![Image 1](image1.png)
![Image 2](image2.png)
![Image 3](image3.png)
"#;

    let image_count = ImageCount::from_markdown(markdown).unwrap();
    assert_eq!(image_count, ImageCount(3));
}