Extend task list parsing (#99)

* Handle task lists that start with * or + symbol
* Handle task lists that start with numbers
* Limit numbers valid for task lists to 9 digits
This commit is contained in:
Łukasz Rutkowski 2019-02-18 12:36:53 +01:00 committed by Dimitry
parent 66bfad16ca
commit 1d3255ed59
2 changed files with 60 additions and 3 deletions

View File

@ -23,7 +23,7 @@ import java.util.regex.Pattern;
@SuppressWarnings("WeakerAccess")
class TaskListBlockParser extends AbstractBlockParser {
private static final Pattern PATTERN = Pattern.compile("\\s*-\\s+\\[(x|X|\\s)\\]\\s+(.*)");
private static final Pattern PATTERN = Pattern.compile("\\s*([-*+]|\\d{1,9}[.)])\\s+\\[(x|X|\\s)]\\s+(.*)");
private final TaskListBlock block = new TaskListBlock();
@ -88,9 +88,9 @@ class TaskListBlockParser extends AbstractBlockParser {
continue;
}
listItem = new TaskListItem()
.done(isDone(matcher.group(1)))
.done(isDone(matcher.group(2)))
.indent(item.indent / 2);
inlineParser.parse(matcher.group(2), listItem);
inlineParser.parse(matcher.group(3), listItem);
block.appendChild(listItem);
}
}

View File

@ -0,0 +1,57 @@
input: |-
- [ ] First
- [x] Second
- [X] Third
* [ ] First star
* [x] Second star
* [X] Third star
+ [ ] First plus
+ [x] Second plus
+ [X] Third plus
1. [x] Number with dot
3) [ ] Number
output:
- task-list: "First"
blockIdent: 1
done: false
- text: "\n"
- task-list: "Second"
blockIdent: 1
done: true
- text: "\n"
- task-list: "Third"
blockIdent: 1
done: true
- text: "\n"
- task-list: "First star"
blockIdent: 1
done: false
- text: "\n"
- task-list: "Second star"
blockIdent: 1
done: true
- text: "\n"
- task-list: "Third star"
blockIdent: 1
done: true
- text: "\n"
- task-list: "First plus"
blockIdent: 1
done: false
- text: "\n"
- task-list: "Second plus"
blockIdent: 1
done: true
- text: "\n"
- task-list: "Third plus"
blockIdent: 1
done: true
- text: "\n"
- task-list: "Number with dot"
blockIdent: 1
done: true
- text: "\n"
- task-list: "Number"
blockIdent: 1
done: false