add title parsing
This commit is contained in:
parent
6d41d63508
commit
8b4da69fb3
@ -1,3 +1,4 @@
|
||||
# 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
|
||||
|
||||
18
src/md.rs
18
src/md.rs
@ -136,6 +136,23 @@ impl Markdown for Document {
|
||||
fn from_md(md: String) -> anyhow::Result<Self> {
|
||||
let mut document = Document::default();
|
||||
for line in md.lines() {
|
||||
if document.title.is_none() {
|
||||
let mut chars = line.chars().peekable();
|
||||
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());
|
||||
}
|
||||
}
|
||||
if let Ok(entry) = Entry::from_md(line.to_string()) {
|
||||
document.entries.push(entry);
|
||||
}
|
||||
@ -143,3 +160,4 @@ impl Markdown for Document {
|
||||
Ok(document)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user