use std::collections::BTreeMap;
use std::fmt;
use sim_kernel::Expr;
#[derive(Clone, Debug, PartialEq)]
pub struct MarkupDoc {
pub title: Option<String>,
pub blocks: Vec<MarkupBlock>,
pub attrs: BTreeMap<String, Expr>,
pub source: Option<SourceDoc>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct SourceDoc {
pub backend: BackendId,
pub text: String,
}
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct BackendId(
pub String,
);
impl BackendId {
pub fn new(id: impl Into<String>) -> Self {
Self(id.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for BackendId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Span {
pub start: usize,
pub end: usize,
pub state: SpanState,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum SpanState {
Preserved,
Dirty,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MathSource {
pub notation: String,
pub text: String,
}
#[derive(Clone, Debug, PartialEq)]
pub enum MarkupBlock {
Heading {
level: u8,
text: Vec<Inline>,
id: Option<String>,
span: Option<Span>,
},
Paragraph {
content: Vec<Inline>,
span: Option<Span>,
},
CodeBlock {
lang: Option<String>,
code: String,
span: Option<Span>,
},
MathBlock {
source: MathSource,
span: Option<Span>,
},
Quote {
blocks: Vec<MarkupBlock>,
span: Option<Span>,
},
List {
ordered: bool,
items: Vec<Vec<MarkupBlock>>,
span: Option<Span>,
},
Table {
header: Vec<Vec<Inline>>,
rows: Vec<Vec<Vec<Inline>>>,
span: Option<Span>,
},
Figure {
src: String,
caption: Vec<Inline>,
span: Option<Span>,
},
Raw {
backend: BackendId,
text: String,
span: Option<Span>,
},
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Inline {
Text(String),
Emph(Vec<Inline>),
Strong(Vec<Inline>),
Code(String),
Link {
label: Vec<Inline>,
target: String,
},
Math(MathSource),
Raw {
backend: BackendId,
text: String,
},
}