fix date formatting when converting back to md

This commit is contained in:
mxhagen 2024-09-25 11:30:54 +02:00
parent 8b4da69fb3
commit a619e913d7
2 changed files with 76 additions and 76 deletions

View File

@ -1,71 +1,67 @@
# Example TODO List
- [ ] ((2024-06-20 21:00)) Take out the trash
- [x] ((2024-06-20 16:00)) Get groceries
- [ ] ((2024-06-20 20:00)) Do the dishes
- [x] This is an extremely long todo entry without a date and yet it has already been completed. there is no way it will all fit in one line, right? i sure hope that doesn't cause any trouble for the end user.
- [ ] didnt
- [ ] you
- [ ] know
- [ ] you
- [ ] were
- [ ] freaky
- [ ] like
- [ ] that
- [ ] can
- [ ] i
- [ ] pay
- [ ] with
- [ ] mousepay
- [ ] here
- [ ] man
- [ ] tiktok
- [ ] is
- [ ] actually
- [ ] hilarious
- [ ] though
- [ ] there
- [ ] is
- [ ] also
- [ ] some
- [ ] baddies
- [ ] with
- [ ] fat
- [ ] honkers
- [ ] on
- [ ] there
- [ ] that
- [ ] have
- [ ] nice
- [ ] smiles
- [ ] and
- [ ] sometimes
- [ ] personalities
- [ ] oh
- [ ] yeeah
- [ ] baby
- [ ] they
- [ ] are
- [ ] real
- [ ] hot
- [ ] babes
- [ ] i
- [ ] hope
- [ ] to
- [ ] see
- [ ] such
- [ ] nice
- [ ] melons
- [ ] in
- [ ] person
- [ ] one
- [ ] day
- [ ] but
- [ ] for
- [ ] that
- [ ] i
- [ ] would
- [ ] probably
- [ ] need
- [ ] to
- [ ] go
- [ ] outside
- [ ] (2024-06-20 21:00) Take out the trash
- [x] (2024-06-20 16:00) Get groceries
- [ ] (2024-06-20 20:00) Do the dishes
- [x] This is an extremely long TODO entry without a date and yet it has already been completed. there is no way it will all fit in one line, right? i sure hope that doesn't cause any trouble for the end user of the application.
- [ ] More TODOs
- [ ] There's a lot to do
- [ ] Man still going
- [ ] Almost never ending TODOs
- [ ] I sure hope scrolling through them works properly
- [ ] Maybe this is just to test that out
- [ ] Or maybe it isn't who knows
- [ ] Nah im joking it is
- [ ] Did
- [ ] you
- [ ] know
- [ ] a
- [ ] pengiun
- [ ] named
- [ ] nils
- [ ] olav
- [ ] III
- [ ] achieved
- [ ] knighthood
- [ ] in
- [ ] 2008
- [ ] in
- [ ] edinburgh
- [ ] zoo
- [ ] That's
- [ ] crazy
- [ ] is
- [ ] it
- [ ] not?
- [ ] I
- [ ] couldn't
- [ ] believe
- [ ] it
- [ ] at
- [ ] first
- [ ] either
- [ ] but
- [ ] I
- [ ] do
- [ ] think
- [ ] it
- [ ] is
- [x] awesome
- [ ] that
- [ ] a
- [x] pengiun
- [ ] gets
- [ ] such
- [ ] recognition
- [ ] I
- [ ] think
- [ ] he
- [ ] deserves
- [ ] it
- [x] and
- [ ] he
- [ ] also
- [ ] deserves
- [ ] a
- [x] fish
- [x] Anyway this is the last TODO entry and should be accessible, if you are reading this: congratulations

View File

@ -30,8 +30,13 @@ pub trait Markdown {
impl Markdown for Entry {
fn to_md(&self) -> String {
let mut md = format!("- [{}] ", if self.done { "x" } else { " " });
if let Some(deadline) = self.deadline {
md += &format!("({}) ", deadline.format("(%Y-%m-%d %H:%M)"));
match self.deadline {
Some(deadline) => md += &format!("{} ", deadline.format("(%Y-%m-%d %H:%M)")),
None => {
md += &std::iter::repeat(' ')
.take("(YYYY-mm-dd HH:MM) ".len())
.collect::<String>()
}
}
md += &self.text;
md
@ -141,14 +146,14 @@ impl Markdown for Document {
let mut count = 0;
while chars.peek().is_some_and(|c| c.is_ascii_whitespace()) {
chars.next();
};
}
while chars.peek().is_some_and(|&c| c == '#') {
count += 1;
chars.next();
};
}
while chars.peek().is_some_and(|c| c.is_ascii_whitespace()) {
chars.next();
};
}
if count == 1 {
document.title = Some(chars.collect());
}
@ -160,4 +165,3 @@ impl Markdown for Document {
Ok(document)
}
}