Files
marginal/src/ast.rs

37 lines
839 B
Rust

use std::fmt::Display;
#[derive(Debug, PartialEq)]
pub enum Inline {
Bold { inner: Vec<Inline> },
Italic { inner: Vec<Inline> },
Link { inner: Vec<Inline>, href: Href },
Code { content: String },
Text { content: String },
}
#[derive(Debug, PartialEq)]
pub struct Href(pub String);
impl Href {
pub fn new(href: &str) -> Self {
// can check for link correctness
Self(href.to_string())
}
}
impl Display for Href {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, PartialEq)]
pub enum Block {
Heading { inner: Vec<Inline>, level: u8 },
Code { content: String, lang: String },
Quote { inner: Box<Block> },
Paragraph { inner: Vec<Inline> },
List { ordered: bool, items: Vec<Block> },
Null,
}