pub fn render_markdown(ast: &Document, config: Config) -> StringExpand description
Render a Markdown AST back to formatted Markdown text
This function takes a parsed Markdown document (AST) and renders it back to clean, well-formatted Markdown text. The output follows consistent formatting rules and can be customized via configuration options.
§Arguments
ast- The Markdown document AST to renderconfig- Configuration options controlling the output format
§Returns
A String containing the formatted Markdown text
§Examples
Basic rendering:
use markdown_ppp::ast::*;
use markdown_ppp::printer::{render_markdown, config::Config};
let doc = Document {
blocks: vec![
Block::Paragraph(vec![
Inline::Text("Hello ".to_string()),
Inline::Strong(vec![Inline::Text("world".to_string())]),
]),
],
};
let config = Config::default();
let markdown = render_markdown(&doc, config);
assert!(markdown.contains("**world**"));With custom width:
use markdown_ppp::ast::Document;
use markdown_ppp::printer::{render_markdown, config::Config};
let doc = Document { blocks: vec![] };
let config = Config::default().with_width(60);
let markdown = render_markdown(&doc, config);§Round-trip Guarantee
For most valid Markdown documents, the following property holds:
parse(render(parse(input))) ≈ parse(input)Where ≈ means semantically equivalent AST structures.