1
0
Fork 0
mirror of https://github.com/archtechx/todo-system.git synced 2025-12-12 00:54:03 +00:00

fix: handle lines starting with # in md files better

This commit is contained in:
Samuel Štancl 2025-09-13 20:21:29 +02:00
parent b1c165b0e8
commit d4bf97ce12
5 changed files with 69 additions and 4 deletions

2
Cargo.lock generated
View file

@ -168,7 +168,7 @@ dependencies = [
[[package]] [[package]]
name = "todos" name = "todos"
version = "0.1.0" version = "0.1.1"
dependencies = [ dependencies = [
"clap", "clap",
"glob", "glob",

View file

@ -1,6 +1,6 @@
[package] [package]
name = "todos" name = "todos"
version = "0.1.0" version = "0.1.1"
edition = "2021" edition = "2021"
authors = ["Samuel Štancl <samuel@archte.ch>"] authors = ["Samuel Štancl <samuel@archte.ch>"]
description = "An intuitive system for organizing TODOs in code" description = "An intuitive system for organizing TODOs in code"

View file

@ -26,3 +26,20 @@ def
- abc - abc
- def - def
```
#!/bin/bash
# call foo with bar argument
foo bar
#comment without space
```
#Example script:
```
#!/bin/bash
# call foo with bar argument
foo bar
#comment without space
```

View file

@ -10,3 +10,15 @@
## Responsivity ## Responsivity
- abc - abc
- [ ] def - [ ] def
```
# make this work
foo bar
#foo bar
```
#example
```
# make this work
foo bar
#foo bar
```

View file

@ -274,13 +274,31 @@ pub fn scan_dir(dir: &Path, entries: &mut Vec<Entry>, excludes: &mut Vec<PathBuf
pub fn scan_todo_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()> { pub fn scan_todo_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()> {
let str = fs::read_to_string(path)?; let str = fs::read_to_string(path)?;
let mut current_category: Option<&str> = None; let mut current_category: Option<&str> = None;
let mut in_code_block = false;
// This can produce: // This can produce:
// - generic todos (above any category) // - generic todos (above any category)
// - category todos (below a ## category heading) // - category todos (below a ## category heading)
// - priority todos (priority keyword part of the line) // - priority todos (priority keyword part of the line)
'line: for (line_num, line) in str.lines().enumerate() { 'line: for (line_num, line) in str.lines().enumerate() {
if line.starts_with('#') { if line.starts_with("```") {
// If we are in an *unindented* code block, we ignore lines
// starting with # - they cannot be headings. Indented
// code blocks are irrelevant.
in_code_block = ! in_code_block;
continue;
}
// We need the line to start with # followed by spaces. So we cannot check just for '#'
// There's also no real need for any complex logic iterating over the line's characters,
// we can just check reasonable heading hierarchy like this. Anything else is unlikely.
if ! in_code_block && (false
|| line.starts_with("# ")
|| line.starts_with("## ")
|| line.starts_with("### ")
|| line.starts_with("#### ")
|| line.starts_with("##### ")
) {
current_category = Some(line.split_once("# ").unwrap().1); current_category = Some(line.split_once("# ").unwrap().1);
continue; continue;
@ -338,13 +356,31 @@ pub fn scan_todo_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()> {
pub fn scan_readme_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()> { pub fn scan_readme_file(path: &Path, entries: &mut Vec<Entry>) -> io::Result<()> {
let str = fs::read_to_string(path)?; let str = fs::read_to_string(path)?;
let mut in_todo_section = false; let mut in_todo_section = false;
let mut in_code_block = false;
// This can produce: // This can produce:
// - generic todos (above any category) // - generic todos (above any category)
// - category todos (below a ## category heading) todo@real add this logic and update README.md // - category todos (below a ## category heading) todo@real add this logic and update README.md
// - priority todos (priority keyword part of the line) // - priority todos (priority keyword part of the line)
'line: for (line_num, line) in str.lines().enumerate() { 'line: for (line_num, line) in str.lines().enumerate() {
if line.starts_with('#') { if line.starts_with("```") {
// If we are in an *unindented* code block, we ignore lines
// starting with # - they cannot be headings. Indented
// code blocks are irrelevant.
in_code_block = ! in_code_block;
continue;
}
// We need the line to start with # followed by spaces. So we cannot check just for '#'
// There's also no real need for any complex logic iterating over the line's characters,
// we can just check reasonable heading hierarchy like this. Anything else is unlikely.
if ! in_code_block && (false
|| line.starts_with("# ")
|| line.starts_with("## ")
|| line.starts_with("### ")
|| line.starts_with("#### ")
|| line.starts_with("##### ")
) {
let section = line.split_once("# ").unwrap().1; let section = line.split_once("# ").unwrap().1;
let cleaned_section = section.to_lowercase().trim_end_matches(':').trim().to_string(); let cleaned_section = section.to_lowercase().trim_end_matches(':').trim().to_string();