1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
//! Markdown pretty-printer for formatting AST back to Markdown
//!
//! This module provides functionality to render a Markdown Abstract Syntax Tree (AST)
//! back to formatted Markdown text. The printer supports configurable formatting
//! options and produces clean, readable Markdown output.
//!
//! # Features
//!
//! - **Full AST support**: All CommonMark + GFM elements are supported
//! - **Configurable formatting**: Control line width, indentation, and spacing
//! - **Pretty-printing**: Intelligent line wrapping and formatting
//! - **Round-trip capability**: Parse → Render → Parse produces equivalent AST
//! - **GitHub extensions**: Tables, task lists, alerts, footnotes, strikethrough
//!
//! # Basic Usage
//!
//! ```rust
//! use markdown_ppp::ast::*;
//! use markdown_ppp::printer::{render_markdown, config::Config};
//!
//! let doc = Document {
//! blocks: vec![
//! Block::Heading(Heading {
//! kind: HeadingKind::Atx(1),
//! content: vec![Inline::Text("Hello World".to_string())],
//! }),
//! Block::Paragraph(vec![
//! Inline::Text("This is ".to_string()),
//! Inline::Strong(vec![Inline::Text("formatted".to_string())]),
//! Inline::Text(" text.".to_string()),
//! ]),
//! ],
//! };
//!
//! let config = Config::default();
//! let markdown = render_markdown(&doc, config);
//! println!("{}", markdown);
//! ```
//!
//! # Configuration
//!
//! Customize the output format using configuration:
//!
//! ```rust
//! use markdown_ppp::printer::{render_markdown, config::Config};
//! use markdown_ppp::ast::{Document, Block, Inline};
//!
//! let config = Config::default().with_width(120);
//! let doc = Document { blocks: vec![Block::Paragraph(vec![Inline::Text("Hello".to_string())])] };
//! let markdown = render_markdown(&doc, config);
//! ```
/// Configuration options for Markdown pretty-printing.
use crate*;
use ;
use Rc;
/// 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 render
/// * `config` - Configuration options controlling the output format
///
/// # Returns
///
/// A `String` containing the formatted Markdown text
///
/// # Examples
///
/// Basic rendering:
/// ```rust
/// 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:
/// ```rust
/// 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:
/// ```text
/// parse(render(parse(input))) ≈ parse(input)
/// ```
/// Where ≈ means semantically equivalent AST structures.