jrnl: markdown generation
This commit is contained in:
parent
0bf5ed0c76
commit
b967f6e90e
2 changed files with 27 additions and 2 deletions
|
@ -2,6 +2,10 @@ use chrono::{DateTime, FixedOffset};
|
|||
use markdown::{Block, Span};
|
||||
use std::convert::identity;
|
||||
|
||||
pub trait ToMd {
|
||||
fn to_md(&self) -> String;
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Doc<'src> {
|
||||
pub entries: Vec<Entry<'src>>,
|
||||
|
@ -35,9 +39,26 @@ impl<'src> Doc<'src> {
|
|||
}
|
||||
}
|
||||
|
||||
impl ToMd for Doc<'_> {
|
||||
fn to_md(&self) -> String {
|
||||
let mut r = "# Journal\n\n".to_owned();
|
||||
|
||||
self.entries.iter().fold(r, |mut r, it| r + &it.to_md())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Entry<'src> {
|
||||
pub timestamp: DateTime<FixedOffset>,
|
||||
pub title: &'src str,
|
||||
pub content: &'src str,
|
||||
}
|
||||
|
||||
impl ToMd for Entry<'_> {
|
||||
fn to_md(&self) -> String {
|
||||
format!(
|
||||
"## {}: {}\n\n{}\n\n",
|
||||
self.timestamp, self.title, self.content
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue