From b6b6cdcd93a43e23be03d003b15f163f8189967e Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Wed, 30 May 2018 09:57:24 -0700 Subject: [PATCH] add dropped todo items '[-]' and make migrate respect indentPattern --- README.md | 2 +- mdbj-migrate/2018-05-07-TEST.md | 12 +++++++++--- mdbj-migrate/migrate.go | 8 ++++---- mdbj-migrate/migrate_test.go | 18 +++++++++--------- mdbj-summary/summary.go | 2 +- mdbj-summary/summary_test.go | 4 ++-- process/process.go | 11 ++++++++--- 7 files changed, 34 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index cce89e3..872fe16 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ The basics of headers with '#' Nested lists with '-' for notes and indentation -Todo and done with '[ ]' and '[x]' +Todo and done with '[ ]' for open todo item, '[x]' for done todo item, and '[-]' for dropped todo item Obviously you can use other markdown features such as **bold**, *italics* and [Links](https://guides.github.com/features/mastering-markdown/) but none of these trigger any special treatment with regards to Markdown Bullet Journal. diff --git a/mdbj-migrate/2018-05-07-TEST.md b/mdbj-migrate/2018-05-07-TEST.md index 76542fc..e49b258 100644 --- a/mdbj-migrate/2018-05-07-TEST.md +++ b/mdbj-migrate/2018-05-07-TEST.md @@ -19,8 +19,10 @@ - asdasd - tabbing - - [x] tabs handled - - [ ] tabs migrated + - [x] tabs handled + - [ ] tabs migrated + - [-] dropping this task but it's not done + - notes # Nothing done @@ -39,4 +41,8 @@ - [ ] not done - [..] partly done -- [x...] completed +- [X...] completed + - [x] completed sub task + - notes + - more notes + - [x] other done task diff --git a/mdbj-migrate/migrate.go b/mdbj-migrate/migrate.go index 97ea02f..59d9df1 100644 --- a/mdbj-migrate/migrate.go +++ b/mdbj-migrate/migrate.go @@ -43,7 +43,7 @@ func (ph *processHandler) NewFile() { ph.flagStack = []process.Flags{} } -func (ph *processHandler) ProcessLine(line string, indentLevel int, headerStack []string, lineStack []string, flags process.Flags) { +func (ph *processHandler) ProcessLine(line string, indentLevel int, indentString string, headerStack []string, lineStack []string, flags process.Flags) { if indentLevel+1 > len(ph.flagStack) { ph.flagStack = append(ph.flagStack, flags) } else { @@ -56,7 +56,7 @@ func (ph *processHandler) ProcessLine(line string, indentLevel int, headerStack if i > indentLevel { break } - if iflags.Done { + if iflags.Done || iflags.Dropped { print = false } } @@ -64,9 +64,9 @@ func (ph *processHandler) ProcessLine(line string, indentLevel int, headerStack if print { if flags.RepTask.Is { - ph.Writeln(strings.Repeat("\t", indentLevel) + "- [ ] 0x" + strconv.Itoa(flags.RepTask.B) + " " + lineStack[len(lineStack)-1]) + ph.Writeln(strings.Repeat(indentString, indentLevel) + "- [ ] 0x" + strconv.Itoa(flags.RepTask.B) + " " + lineStack[len(lineStack)-1]) } else if flags.Todo { - ph.Writeln(strings.Repeat("\t", indentLevel) + "- [ ] " + lineStack[len(lineStack)-1]) + ph.Writeln(strings.Repeat(indentString, indentLevel) + "- [ ] " + lineStack[len(lineStack)-1]) } else { ph.Writeln(line) } diff --git a/mdbj-migrate/migrate_test.go b/mdbj-migrate/migrate_test.go index e4fbb8c..07b7786 100644 --- a/mdbj-migrate/migrate_test.go +++ b/mdbj-migrate/migrate_test.go @@ -12,19 +12,20 @@ import ( const EXPECTED = `# Work - [ ] Write tests - - [ ] migrate + - [ ] migrate # Test Data - note - - [ ] nesting1 - - [ ] nesting 2 - - [ ] nesting 3 - - [ ] nesting 4 + - [ ] nesting 2 + - [ ] nesting 3 + - [ ] nesting 4 - notes of note done thing - tabbing - - [ ] tabs migrated + - [ ] tabs migrated + - notes # Nothing done @@ -36,8 +37,8 @@ const EXPECTED = `# Work - [ ] 0x5 things - [ ] 0x2 other things - [ ] Group - - [ ] 0x3 nesting rep - - [ ] 0x6 done nested rep + - [ ] 0x3 nesting rep + - [ ] 0x6 done nested rep # Pomodoros @@ -75,7 +76,6 @@ func TestMigrate(t *testing.T) { line := strings.Count(string(result[:diffLoc]), "\n") errorStr := string(result[int(math.Max(0, float64(diffLoc - 10))) : int(math.Min(float64(len(result)), float64(diffLoc + 10))) ]) - t.Errorf("Summary results do not match expected:\nfirst difference at line %v: '%v'\n%v<---->\n%v\n", line, errorStr, string(result), EXPECTED) - + t.Errorf("Summary results do not match expected:\nfirst difference at line %v\nexpected char: '%c'\nactual char: '%v'\nline: '%v'\nACTUAL:\n%v<---->\nEXPECTED:\n%v\n", line, EXPECTED[diffLoc], string(result[diffLoc]), errorStr, string(result), EXPECTED) } } \ No newline at end of file diff --git a/mdbj-summary/summary.go b/mdbj-summary/summary.go index d2c5c70..22306a2 100644 --- a/mdbj-summary/summary.go +++ b/mdbj-summary/summary.go @@ -49,7 +49,7 @@ func (ph *processHandler) handleHeaderPrint() { } } -func (ph *processHandler) ProcessLine(line string, indentLevel int, headerStack []string, lineStack []string, flags process.Flags) { +func (ph *processHandler) ProcessLine(line string, indentLevel int, indentString string, headerStack []string, lineStack []string, flags process.Flags) { if strings.Trim(line, " \t\n\r") == "" { return } diff --git a/mdbj-summary/summary_test.go b/mdbj-summary/summary_test.go index 3301c96..758eef3 100644 --- a/mdbj-summary/summary_test.go +++ b/mdbj-summary/summary_test.go @@ -60,6 +60,6 @@ func TestSummary(t *testing.T) { line := strings.Count(string(result[:diffLoc]), "\n") errorStr := string(result[int(math.Max(0, float64(diffLoc - 10))) : int(math.Min(float64(len(result)), float64(diffLoc + 10))) ]) - t.Errorf("Summary results do not match expected:\nfirst difference at line %v\nexpected char: '%c'\nactual char: '%v'\nline: '%v'\n%v<---->\n%v\n", line, EXPECTED[diffLoc], string(result[diffLoc]), errorStr, string(result), EXPECTED) + t.Errorf("Summary results do not match expected:\nfirst difference at line %v\nexpected char: '%c'\nactual char: '%v'\nline: '%v'\nACTUAL:\n%v<---->\nEXPECTED:\n%v\n", line, EXPECTED[diffLoc], string(result[diffLoc]), errorStr, string(result), EXPECTED) } -} +} \ No newline at end of file diff --git a/process/process.go b/process/process.go index f138bb7..ea25786 100644 --- a/process/process.go +++ b/process/process.go @@ -15,7 +15,7 @@ const ( ) var ( - todoTaskExp = regexp.MustCompile("^\\[([ \\.xX]*)\\]") + todoTaskExp = regexp.MustCompile("^\\[([ \\.xX-]*)\\]") startSpaces = regexp.MustCompile("^[\t ]*") repTaskRegExp = regexp.MustCompile("^([0-9]*)[xX]([0-9]*)") headerExp = regexp.MustCompile("^(#+) *(.+)") @@ -29,13 +29,14 @@ type RepTask struct { type Flags struct { Todo bool Done bool + Dropped bool RepTask RepTask Pomodoros int } type ProcessHandler interface { Writeln(line string) - ProcessLine(line string, indentLevel int, headerStack []string, lineStack []string, flags Flags) + ProcessLine(line string, indentLevel int, indentString string, headerStack []string, lineStack []string, flags Flags) Eof() NewFile() } @@ -124,7 +125,7 @@ func ProcessFile(ph ProcessHandler, fileName string) { lineStack = append(lineStack, row) } - ph.ProcessLine(line, indentLevel, headerStack, lineStack, flags) + ph.ProcessLine(line, indentLevel, indentPattern, headerStack, lineStack, flags) } ph.Eof() } @@ -132,6 +133,7 @@ func ProcessFile(ph ProcessHandler, fileName string) { func getText(str string, indentLevel int, indentPattern string) (text string, flags Flags) { //fmt.Printf("indentLevel: %v str: '%s'\n", indentLevel, str ) flags.Done = false + flags.Dropped = false flags.Todo = false flags.RepTask.Is = false flags.Pomodoros = 0 @@ -148,6 +150,9 @@ func getText(str string, indentLevel int, indentPattern string) (text string, fl if strings.ContainsAny(inner, "xX") { flags.Done = true } + if strings.Contains(inner, "-") { + flags.Dropped = true + } flags.Pomodoros = strings.Count(inner, ".") if len(text) > len(inner) + 3 { text = text[len(inner)+3:]