mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +08:00
Allow YAML tags to be a string
This commit is contained in:
@ -190,6 +190,8 @@ class NoteSerializer implements NoteSerializerInterface {
|
||||
note.tags = tags.map((t) => t.toString()).toSet();
|
||||
} else if (tags is List) {
|
||||
note.tags = tags.map((t) => t.toString()).toSet();
|
||||
} else if (tags is String) {
|
||||
note.tags = {tags};
|
||||
} else {
|
||||
Log.e("Note Tags Decoding Failed: $tags");
|
||||
}
|
||||
|
@ -122,5 +122,32 @@ void main() {
|
||||
expect(doc.props['title'], 'Why not?');
|
||||
expect(doc.props['draft'], true);
|
||||
});
|
||||
|
||||
test('Test Non list Tag', () {
|
||||
var props = LinkedHashMap<String, dynamic>.from(<String, dynamic>{
|
||||
"title": "Why not?",
|
||||
"draft": true,
|
||||
"tags": "foo",
|
||||
});
|
||||
var doc = MdYamlDoc("body", props);
|
||||
|
||||
var serializer = NoteSerializer.raw();
|
||||
serializer.settings.saveTitleAsH1 = false;
|
||||
|
||||
var note = Note(parent, "file-path-not-important");
|
||||
serializer.decode(doc, note);
|
||||
|
||||
expect(note.body, "body");
|
||||
expect(note.title, "Why not?");
|
||||
expect(note.extraProps, <String, dynamic>{"draft": true});
|
||||
expect(note.tags, <String>{"foo"});
|
||||
|
||||
serializer.encode(note, doc);
|
||||
expect(doc.body, "body");
|
||||
expect(doc.props['title'], 'Why not?');
|
||||
expect(doc.props['draft'], true);
|
||||
expect(doc.props['tags'], ['foo']);
|
||||
expect(doc.props.length, 3);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user