socketry_markdown/markdown/
mod.rs1#![allow(clippy::pedantic)]
13
14pub use self::configure::{IndentOptions, LineWrapping, Options};
15use self::state::{Info, State};
16use crate::{mdast::Node, message::Message};
17use alloc::string::String;
18
19extern crate alloc;
20mod association;
21mod configure;
22mod construct_name;
23mod handle;
24mod state;
25mod r#unsafe;
26mod util;
27
28pub fn to_markdown(tree: &Node) -> Result<String, Message> {
34 to_markdown_with_options(tree, &Options::default())
35}
36
37pub fn to_markdown_with_options(tree: &Node, options: &Options) -> Result<String, Message> {
44 let mut state = State::new(options);
45 let mut result = state.handle(tree, &Info::new("\n", "\n"), None)?;
46
47 if !result.is_empty() {
48 let last_char = result.chars().last().unwrap();
49 if last_char != '\n' && last_char != '\r' {
50 result.push('\n');
51 }
52 }
53
54 Ok(result)
55}