mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 18:03:14 +08:00
Handle invalid markdown
In these cases we just try to fetch the body the best we can and ignore all the keys. This should give us more info about #4
This commit is contained in:
@ -26,12 +26,18 @@ class MarkdownYAMLSerializer implements NoteSerializer {
|
||||
Note decode(String str) {
|
||||
if (str.startsWith("---\n")) {
|
||||
var parts = str.split("---\n");
|
||||
|
||||
var yamlMap = loadYaml(parts[1]);
|
||||
var map = <String, dynamic>{};
|
||||
yamlMap.forEach((key, value) {
|
||||
map[key] = value;
|
||||
});
|
||||
|
||||
try {
|
||||
var yamlMap = loadYaml(parts[1]);
|
||||
yamlMap.forEach((key, value) {
|
||||
map[key] = value;
|
||||
});
|
||||
} catch (err, stack) {
|
||||
print(
|
||||
'MarkdownYAMLSerializer::decode (${parts[1]}) -> ${err.toString()}');
|
||||
print(stack.toString());
|
||||
}
|
||||
map['body'] = parts[2].trimLeft();
|
||||
|
||||
return Note.fromJson(map);
|
||||
|
@ -31,6 +31,20 @@ void main() {
|
||||
expect(note2, note);
|
||||
});
|
||||
|
||||
test('Markdown Serializer with invalid Markdown', () {
|
||||
var inputNoteStr = """---
|
||||
type
|
||||
---
|
||||
|
||||
Alright.""";
|
||||
|
||||
var serializer = MarkdownYAMLSerializer();
|
||||
var note = serializer.decode(inputNoteStr);
|
||||
var actualStr = "Alright.";
|
||||
|
||||
expect(actualStr, note.body);
|
||||
});
|
||||
|
||||
/*
|
||||
test('Markdown Serializer YAML Order', () {
|
||||
var str = """---
|
||||
|
Reference in New Issue
Block a user