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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#![deny(
missing_docs,
missing_debug_implementations,
missing_copy_implementations,
trivial_casts,
trivial_numeric_casts,
unstable_features,
unused_import_braces
)]
#![allow(
unknown_lints,
clippy::doc_markdown,
cyclomatic_complexity,
clippy::bool_to_int_with_if,
clippy::too_many_arguments
)]
use std::io::BufWriter;
pub mod adapters;
pub mod arena_tree;
mod cm;
mod ctype;
mod entity;
pub mod html;
pub mod nodes;
mod parser;
pub mod plugins;
mod scanners;
mod strings;
#[cfg(test)]
mod tests;
mod xml;
pub use cm::format_document as format_commonmark;
pub use cm::format_document_with_plugins as format_commonmark_with_plugins;
pub use html::format_document as format_html;
pub use html::format_document_with_plugins as format_html_with_plugins;
pub use html::Anchorizer;
pub use parser::{
parse_document, parse_document_with_broken_link_callback, ComrakExtensionOptions,
ComrakOptions, ComrakParseOptions, ComrakPlugins, ComrakRenderOptions, ComrakRenderPlugins,
ListStyleType,
};
pub use typed_arena::Arena;
pub use xml::format_document as format_xml;
pub use xml::format_document_with_plugins as format_xml_with_plugins;
pub fn markdown_to_html(md: &str, options: &ComrakOptions) -> String {
markdown_to_html_with_plugins(md, options, &ComrakPlugins::default())
}
pub fn markdown_to_html_with_plugins(
md: &str,
options: &ComrakOptions,
plugins: &ComrakPlugins,
) -> String {
let arena = Arena::new();
let root = parse_document(&arena, md, options);
let mut bw = BufWriter::new(Vec::new());
format_html_with_plugins(root, options, &mut bw, plugins).unwrap();
String::from_utf8(bw.into_inner().unwrap()).unwrap()
}
pub fn version() -> &'static str {
env!("CARGO_PKG_VERSION")
}
pub fn markdown_to_commonmark(md: &str, options: &ComrakOptions) -> String {
let arena = Arena::new();
let root = parse_document(&arena, md, options);
let mut bw = BufWriter::new(Vec::new());
format_commonmark(root, options, &mut bw).unwrap();
String::from_utf8(bw.into_inner().unwrap()).unwrap()
}
pub fn markdown_to_commonmark_xml(md: &str, options: &ComrakOptions) -> String {
markdown_to_commonmark_xml_with_plugins(md, options, &ComrakPlugins::default())
}
pub fn markdown_to_commonmark_xml_with_plugins(
md: &str,
options: &ComrakOptions,
plugins: &ComrakPlugins,
) -> String {
let arena = Arena::new();
let root = parse_document(&arena, md, options);
let mut bw = BufWriter::new(Vec::new());
format_xml_with_plugins(root, options, &mut bw, plugins).unwrap();
String::from_utf8(bw.into_inner().unwrap()).unwrap()
}