Checklist: Maintain the case of 'x'

This commit is contained in:
Vishesh Handa
2020-04-14 17:46:24 +02:00
parent 40d613b60c
commit f53aa53683
2 changed files with 22 additions and 3 deletions

View File

@ -190,6 +190,8 @@ class TaskListSyntax extends md.InlineSyntax {
var m = match[1].trim();
if (m.isNotEmpty) {
el.attributes['xUpperCase'] = (m[0] == 'X').toString();
} else {
el.attributes['xUpperCase'] = "false";
}
el.attributes['text'] = '${match[2]}';
parser.addNode(el);
@ -259,12 +261,13 @@ class CustomRenderer implements md.NodeVisitor {
if (tag == 'input') {
var el = element;
if (el is md.Element && el.attributes['type'] == 'checkbox') {
assert(el.attributes.containsKey('xUpperCase'));
bool val = el.attributes['checked'] != 'false';
if (val) {
if (el.attributes['xUpperCase'] != 'false') {
buffer.write('[x] ');
} else {
buffer.write('[X] ');
} else {
buffer.write('[x] ');
}
} else {
buffer.write('[ ] ');

View File

@ -94,7 +94,7 @@ How are you doing?
[x] item 1
[ ] Foo
[X] item 3
[x] item 3
[ ] item 4
Booga Wooga
@ -226,5 +226,21 @@ Booga Wooga
note = checklist.note;
expect(note.body, "[ ] One\n[ ]Two\n[ ] Three\n[ ] Four\n[ ] Five\n");
});
test('Maintain x case', () async {
var content = "[X] One\n[ ]Two";
var notePath = p.join(tempDir.path, "note448.md");
await File(notePath).writeAsString(content);
var parentFolder = NotesFolderFS(null, tempDir.path);
var note = Note(parentFolder, notePath);
await note.load();
var checklist = Checklist(note);
note = checklist.note;
expect(note.body, content);
});
});
}