use render::html::RenderHTML;
pub mod ast;
pub mod ast_elements;
pub mod text_block;
pub mod render;
pub mod error;
#[cfg(test)]
pub mod tests;
type TextFormatInnerElement = Vec<TextFormat>;
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct AST {
pub root: Vec<ASTElement>,
}
pub fn parse_to_ast_model(input: &str) -> AST {
AST::parser(input)
}
pub fn md_to_html(input: &str) -> Result<String, error::CorrError> {
let ast_model = AST::parser(input);
AST::render(&ast_model)
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ASTElement {
Heading {
text: FormattedTextBlock,
tier: u8,
},
TextBlock {
text: FormattedTextBlock,
},
Liste {
elements: Vec<ListItem>,
},
Image {
link_text: Option<String>,
link_url: Option<String>,
image_alt: Option<String>,
image_url: String,
},
Table {
headers: Vec<FormattedTextBlock>,
inhalt: Vec<Vec<FormattedTextBlock>>,
},
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ListItemType {
Ordered(usize),
Unordered,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct ListItem {
pub item_type: ListItemType,
pub level: usize,
pub content: FormattedTextBlock,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct FormattedTextBlock {
pub inhalt: Vec<TextFormat>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum TextFormat {
Bold(TextFormatInnerElement),
Italic(TextFormatInnerElement),
StrikeThrough(TextFormatInnerElement),
Link {
name: TextFormatInnerElement,
href: String,
},
Text(String),
}