#[derive(Debug, Clone, PartialEq)]
pub struct Schema {
pub opts: SchemaOpts,
pub frontmatter: Vec<FieldSchema>,
pub body: Vec<Node>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SchemaOpts {
pub ordered: bool,
pub strict: bool,
pub frontmatter_open: bool,
}
impl Default for SchemaOpts {
fn default() -> Self {
SchemaOpts {
ordered: true,
strict: true,
frontmatter_open: false,
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct FieldSchema {
pub key: String,
pub alias: String,
pub optional: bool,
pub ty: FieldType,
pub desc: Option<String>,
}
#[derive(Debug, Clone, PartialEq)]
pub enum FieldType {
Str,
Int,
Bool,
Date,
Enum(Vec<String>),
List(Box<FieldType>),
Regex(String),
}
#[derive(Debug, Clone, PartialEq)]
pub enum Node {
Heading {
level: u8,
title: Match,
head: Head,
children: Vec<Node>,
},
List {
style: ListStyle,
item: Option<Match>,
head: Head,
children: Vec<Node>,
},
Prose {
text: Option<Match>,
head: Head,
},
}
impl Node {
pub(crate) fn set_children(&mut self, kids: Vec<Node>) {
match self {
Node::Heading { children, .. } | Node::List { children, .. } => *children = kids,
Node::Prose { .. } => {}
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Head {
pub name: Option<String>,
pub card: Card,
pub desc: Option<String>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ListStyle {
Bullet,
Ordered,
Checklist,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Match {
Literal(String),
Regex(String),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Card {
#[default]
Required,
Optional,
Star,
Plus,
Range(u32, Option<u32>),
}