Checklist Parser: Make it a bit more robust

Allow the space after `[ ]` to be optional. Just like in Github.
This commit is contained in:
Vishesh Handa
2020-05-01 18:44:38 +02:00
parent 01db30c613
commit 70ec10b7bc
2 changed files with 5 additions and 5 deletions

View File

@ -43,7 +43,7 @@ class ChecklistItem {
class Checklist { class Checklist {
static final _pattern = RegExp( static final _pattern = RegExp(
r'^(.*)- \[([ xX])\] +(.*)$', r'^(.*)- \[([ xX])\] ?(.*)$',
multiLine: false, multiLine: false,
); );

View File

@ -186,11 +186,11 @@ Booga Wooga
var checklist = Checklist(note); var checklist = Checklist(note);
note = checklist.note; note = checklist.note;
expect(note.body, "Hi.\n- [ ] One\n- Two\n- [ ] \n- [ ] "); expect(note.body, "Hi.\n- [ ] One\n- Two\n- [ ] \n- [ ] ");
}); });
test('Does not add extra new line', () async { test('Does not add extra new line', () async {
var content = "- [ ] One\n- [ ]Two\n- [ ] Three\n- [ ] Four\n"; var content = "- [ ] One\n- [ ]Two\n- [ ] Three\n- [ ]Four\n";
var notePath = p.join(tempDir.path, "note449.md"); var notePath = p.join(tempDir.path, "note449.md");
await File(notePath).writeAsString(content); await File(notePath).writeAsString(content);
@ -204,11 +204,11 @@ Booga Wooga
note = checklist.note; note = checklist.note;
expect(note.body, expect(note.body,
"- [ ] One\n- [ ]Two\n- [ ] Three\n- [ ] Four\n- [ ] Five\n"); "- [ ] One\n- [ ] Two\n- [ ] Three\n- [ ] Four\n- [ ] Five\n");
}); });
test('Maintain x case', () async { test('Maintain x case', () async {
var content = "- [X] One\n- [ ]Two"; var content = "- [X] One\n- [ ] Two";
var notePath = p.join(tempDir.path, "note448.md"); var notePath = p.join(tempDir.path, "note448.md");
await File(notePath).writeAsString(content); await File(notePath).writeAsString(content);