use socketry_markdown::{
LineWrapping, MarkdownOptions, ParseOptions, message::Message, to_markdown_with_options,
to_mdast,
};
pub fn normalize_document(source: &str) -> Result<String, Message> {
let mut options = ParseOptions::gfm();
options.constructs.frontmatter = true;
options.constructs.math_flow = true;
options.constructs.math_text = true;
normalize_document_with_options(source, &options)
}
pub fn normalize_document_with_options(
source: &str,
parse_options: &ParseOptions,
) -> Result<String, Message> {
let tree = to_mdast(source, parse_options)?;
to_markdown_with_options(
&tree,
&MarkdownOptions {
line_wrapping: LineWrapping::Unwrap,
..MarkdownOptions::default()
},
)
}
mod file_system;
use std::path::PathBuf;
#[bake::task]
pub fn normalize(
context: &mut bake::Context,
#[bake(positional, help = "Markdown files, relative to the project root.")] paths: Vec<PathBuf>,
) -> bake::Result<String> {
let changed = file_system::normalize_files(context.root(), &paths)?;
Ok(format!(
"Normalized {changed} of {} Markdown files",
paths.len()
))
}
#[cfg(test)]
#[path = "tests.rs"]
mod tests;