add dropped todo items '[-]' and make migrate respect indentPattern

This commit is contained in:
Dan Ballard 2018-05-30 09:57:24 -07:00
parent 42eb9019d4
commit b6b6cdcd93
7 changed files with 34 additions and 23 deletions

View File

@ -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.

View File

@ -21,6 +21,8 @@
- tabbing
- [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

View File

@ -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)
}

View File

@ -25,6 +25,7 @@ const EXPECTED = `# Work
- notes of note done thing
- tabbing
- [ ] tabs migrated
- notes
# Nothing done
@ -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)
}
}

View File

@ -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
}

View File

@ -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)
}
}

View File

@ -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:]