Skip to main content

node_path

Macro node_path 

Source
macro_rules! node_path {
    ($arena:expr, $start:expr $(, $method:ident )* ) => { ... };
}
Expand description

Helper macro to traverse the AST by calling methods on nodes.

ยงExamples

use rushdown::md_ast;
use rushdown::node_path;
use rushdown::as_kind_data;
use rushdown::ast::*;
use rushdown::renderer::html;

let mut arena = Arena::new();
let doc = md_ast!(&mut arena, Document::new() => {
    Blockquote::new() => {
        Paragraph::new(); { |node: &mut Node| {
            node.attributes_mut().insert("class", "paragraph".into());
        } } => {
            Text::new("Hello, World!")
        },
        Paragraph::new() => {
            Text::new("This is a test.")
        }
    }
});
let text_opt = node_path!(arena, doc, first_child, first_child, first_child);
assert_eq!(as_kind_data!(arena, text_opt.unwrap(), Text).str(""), "Hello, World!");