From a619e913d722e6a30b257f950c88b8b3c91ea134 Mon Sep 17 00:00:00 2001 From: mxhagen Date: Wed, 25 Sep 2024 11:30:54 +0200 Subject: [PATCH] fix date formatting when converting back to md --- example_todo.md | 136 +++++++++++++++++++++++------------------------- src/md.rs | 16 +++--- 2 files changed, 76 insertions(+), 76 deletions(-) diff --git a/example_todo.md b/example_todo.md index a9465c0..d7a8846 100644 --- a/example_todo.md +++ b/example_todo.md @@ -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 diff --git a/src/md.rs b/src/md.rs index 4e6952c..e99f40b 100644 --- a/src/md.rs +++ b/src/md.rs @@ -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::() + } } 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) } } -