feat: markdown implementation #18

Merged
Anri merged 9 commits from feat/md into main 2023-04-11 01:25:45 +02:00
Showing only changes of commit dfa62c8e07 - Show all commits

View file

@ -22,7 +22,7 @@ enum FrontMatter<'a> {
}
impl FrontMatter<'_> {
fn parse(&self) -> Metadata {
fn parse(&self) -> FileMetadata {
match self {
Self::Yaml(val) => serde_yaml::from_str(val).unwrap_or_default(),
Self::Toml(_val) => todo!(),
@ -32,8 +32,13 @@ impl FrontMatter<'_> {
}
#[derive(Default, Deserialize)]
pub struct Metadata {
pub struct FileMetadata {
pub title: Option<String>,
pub link: Option<String>,
}
pub struct Metadata {
pub info: FileMetadata,
pub mermaid: bool,
}
@ -65,7 +70,7 @@ pub fn read_md(filename: &str) -> (Metadata, String) {
markdown::mdast::Node::Yaml(v) => FrontMatter::Yaml(&v.value).parse(),
markdown::mdast::Node::Toml(v) => FrontMatter::Toml(&v.value).parse(),
markdown::mdast::Node::MdxjsEsm(v) => FrontMatter::Json(&v.value).parse(),
_ => Metadata::default(),
_ => FileMetadata::default(),
};
// Convert to HTML
@ -92,8 +97,8 @@ pub fn read_md(filename: &str) -> (Metadata, String) {
(
Metadata {
info: metadata,
mermaid: presence_mermaid,
..metadata
},
html,
)