Skip to main content

md_ast

Macro md_ast 

Source
macro_rules! md_ast {
    ($arena:expr, $root:expr => { $($children:tt)* }) => { ... };
    (@mk $arena:expr, $spec:expr) => { ... };
    (@mk $arena:expr, $spec:expr, @{ $post:expr }) => { ... };
    (@children $arena:expr, $parent:ident, { }) => { ... };
    (@children $arena:expr, $parent:ident, {
        $child:expr $( ;{ $post:expr } )? => { $($grand:tt)* } $(, $($rest:tt)*)?
    }) => { ... };
    (@children $arena:expr, $parent:ident, {
        $child:expr $( ;{ $post:expr } )? $(, $($rest:tt)*)?
    }) => { ... };
}
Expand description

Helper macro to construct an AST.

ยงExamples

use rushdown::md_ast;
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 renderer = html::Renderer::with_options(html::Options::default());
let mut output = String::new();
renderer.render(&mut output, "", &arena, doc).expect("Failed to render HTML");
assert_eq!(output, "<blockquote>\n<p class=\"paragraph\">Hello, World!</p>\n<p>This is a test.</p>\n</blockquote>\n");