mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 10:17:16 +08:00
Checklist Parser: Make it a bit more robust
Allow the space after `[ ]` to be optional. Just like in Github.
This commit is contained in:
@ -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,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
Reference in New Issue
Block a user