#[derive(Debug, Clone, PartialEq)]
pub enum Node {
Block(BlockNode),
Inline(InlineNode),
}
#[derive(Debug, Clone, PartialEq)]
pub enum BlockNode {
Document(Vec<BlockNode>),
Heading {
level: u8,
content: Vec<InlineNode>,
},
Paragraph(Vec<InlineNode>),
BlockQuote(Vec<BlockNode>),
CodeBlock {
language: Option<String>,
content: String,
},
UnorderedList(Vec<ListItem>),
OrderedList {
start: u32,
items: Vec<ListItem>,
},
ThematicBreak,
Table {
headers: Vec<InlineNode>,
rows: Vec<Vec<InlineNode>>,
alignments: Vec<Alignment>,
},
HtmlBlock(String),
}
#[derive(Debug, Clone, PartialEq)]
pub enum InlineNode {
Text(String),
Emphasis(Vec<InlineNode>),
Strong(Vec<InlineNode>),
Strike(Vec<InlineNode>),
InlineCode(String),
Link {
url: String,
title: Option<String>,
content: Vec<InlineNode>,
},
Image {
url: String,
title: Option<String>,
alt: String,
},
InlineContainer(Vec<InlineNode>),
HtmlElement(HtmlElement),
SoftBreak,
HardBreak,
}
#[derive(Debug, Clone, PartialEq)]
pub enum ListItem {
Regular {
content: Vec<BlockNode>,
},
Task {
completed: bool,
content: Vec<BlockNode>,
},
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Alignment {
None,
Left,
Center,
Right,
}
#[derive(Debug, Clone, PartialEq)]
pub struct HtmlAttribute {
pub name: String,
pub value: String,
}
#[derive(Debug, Clone, PartialEq)]
pub struct HtmlElement {
pub tag: String,
pub attributes: Vec<HtmlAttribute>,
pub children: Vec<InlineNode>,
pub self_closing: bool,
}
impl BlockNode {
pub fn into_node(self) -> Node {
Node::Block(self)
}
}
impl InlineNode {
pub fn into_node(self) -> Node {
Node::Inline(self)
}
}