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 # Example TODO List
- [ ] ((2024-06-20 21:00)) Take out the trash
- [x] ((2024-06-20 16:00)) Get groceries - [ ] (2024-06-20 21:00) Take out the trash
- [ ] ((2024-06-20 20:00)) Do the dishes - [x] (2024-06-20 16:00) Get groceries
- [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. - [ ] (2024-06-20 20:00) Do the dishes
- [ ] didnt - [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.
- [ ] you - [ ] More TODOs
- [ ] know - [ ] There's a lot to do
- [ ] you - [ ] Man still going
- [ ] were - [ ] Almost never ending TODOs
- [ ] freaky - [ ] I sure hope scrolling through them works properly
- [ ] like - [ ] Maybe this is just to test that out
- [ ] that - [ ] Or maybe it isn't who knows
- [ ] can - [ ] Nah im joking it is
- [ ] i - [ ] Did
- [ ] pay - [ ] you
- [ ] with - [ ] know
- [ ] mousepay - [ ] a
- [ ] here - [ ] pengiun
- [ ] man - [ ] named
- [ ] tiktok - [ ] nils
- [ ] is - [ ] olav
- [ ] actually - [ ] III
- [ ] hilarious - [ ] achieved
- [ ] though - [ ] knighthood
- [ ] there - [ ] in
- [ ] is - [ ] 2008
- [ ] also - [ ] in
- [ ] some - [ ] edinburgh
- [ ] baddies - [ ] zoo
- [ ] with - [ ] That's
- [ ] fat - [ ] crazy
- [ ] honkers - [ ] is
- [ ] on - [ ] it
- [ ] there - [ ] not?
- [ ] that - [ ] I
- [ ] have - [ ] couldn't
- [ ] nice - [ ] believe
- [ ] smiles - [ ] it
- [ ] and - [ ] at
- [ ] sometimes - [ ] first
- [ ] personalities - [ ] either
- [ ] oh - [ ] but
- [ ] yeeah - [ ] I
- [ ] baby - [ ] do
- [ ] they - [ ] think
- [ ] are - [ ] it
- [ ] real - [ ] is
- [ ] hot - [x] awesome
- [ ] babes - [ ] that
- [ ] i - [ ] a
- [ ] hope - [x] pengiun
- [ ] to - [ ] gets
- [ ] see - [ ] such
- [ ] such - [ ] recognition
- [ ] nice - [ ] I
- [ ] melons - [ ] think
- [ ] in - [ ] he
- [ ] person - [ ] deserves
- [ ] one - [ ] it
- [ ] day - [x] and
- [ ] but - [ ] he
- [ ] for - [ ] also
- [ ] that - [ ] deserves
- [ ] i - [ ] a
- [ ] would - [x] fish
- [ ] probably - [x] Anyway this is the last TODO entry and should be accessible, if you are reading this: congratulations
- [ ] need
- [ ] to
- [ ] go
- [ ] outside

View File

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