use std::path::PathBuf;
#[derive(Debug, Clone, Copy)]
pub struct MarkdownSource {
pub slug: &'static str,
pub content: &'static str,
}
#[derive(Debug, Clone, serde::Deserialize)]
pub struct MarkdownFrontmatter {
pub title: String,
#[serde(default)]
pub description: String,
#[serde(default)]
pub order: u32,
}
#[derive(Debug, Clone)]
pub struct MarkdownPage {
pub slug: String,
pub frontmatter: MarkdownFrontmatter,
pub body: String,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct TocItem {
pub level: u8,
pub id: String,
pub text: String,
}
#[derive(Debug, Clone, Copy)]
pub struct RenderOptions {
pub enable_tables: bool,
pub enable_strikethrough: bool,
pub enable_tasklists: bool,
}
impl Default for RenderOptions {
fn default() -> Self {
Self {
enable_tables: true,
enable_strikethrough: true,
enable_tasklists: true,
}
}
}
#[derive(Debug, Clone)]
pub struct RenderedMarkdown {
pub html: String,
pub toc: Vec<TocItem>,
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum MarkdownError {
#[error("frontmatter delimiters `+++` not found in '{slug}'")]
FrontmatterMissing {
slug: String,
},
#[error("frontmatter TOML parse error in '{slug}': {source}")]
FrontmatterInvalid {
slug: String,
#[source]
source: toml::de::Error,
},
#[error("I/O error reading '{path}': {source}")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("file name cannot be converted to a slug: '{name}'")]
InvalidFileName {
name: String,
},
#[error("duplicate slug '{slug}' in registry")]
DuplicateSlug {
slug: String,
},
}