Skip to main content

mdx/
lib.rs

1use itertools::Itertools;
2
3// mod headings;
4// mod mdx_ast;
5// mod mdx_error;
6pub mod ast;
7pub use ast::{mdx_elements, MdxAst};
8
9#[derive(Debug, PartialEq, Eq)]
10pub struct Mdx<'a> {
11    pub ast: Vec<MdxAst<'a>>,
12}
13
14pub fn parse(
15    input: &str,
16) -> Result<Mdx, nom_supreme::error::ErrorTree<nom_supreme::final_parser::Location>> {
17    mdx_elements(input).map(|ast| Mdx { ast })
18}
19
20// TODO: there's probably a trait we can do for this?
21// maybe Display somehow?
22pub fn stringify(m: Mdx) -> String {
23    m.ast
24        .iter()
25        .map(|ast| format!("{}", ast))
26        .intersperse("\n\n".to_string())
27        .collect::<String>()
28}