mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 11:33:34 +08:00
Revert "MdYamlDoc: Add a very basic reverse implementation"
This reverts commit a8af8d795eafce8d9ed7f4be2ee2cc47d8f945b3. This complicates everything too much.
This commit is contained in:
@ -7,10 +7,6 @@ import 'package:gitjournal/utils/logger.dart';
|
|||||||
import 'md_yaml_doc.dart';
|
import 'md_yaml_doc.dart';
|
||||||
|
|
||||||
class MarkdownYAMLCodec {
|
class MarkdownYAMLCodec {
|
||||||
bool reverse;
|
|
||||||
|
|
||||||
MarkdownYAMLCodec({this.reverse = false});
|
|
||||||
|
|
||||||
MdYamlDoc decode(String str) {
|
MdYamlDoc decode(String str) {
|
||||||
const startYamlStr = "---\n";
|
const startYamlStr = "---\n";
|
||||||
const endYamlStr = "\n---\n";
|
const endYamlStr = "\n---\n";
|
||||||
@ -60,23 +56,6 @@ class MarkdownYAMLCodec {
|
|||||||
return MdYamlDoc(body: body, props: map);
|
return MdYamlDoc(body: body, props: map);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str.endsWith(endYamlStr)) {
|
|
||||||
var endYamlPos = str.length - endYamlStr.length;
|
|
||||||
var startYamlPos = str.lastIndexOf(startYamlStr, endYamlPos);
|
|
||||||
if (startYamlPos == -1) {
|
|
||||||
return MdYamlDoc(body: str);
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: What if there is nothing afterwards?
|
|
||||||
var yamlText =
|
|
||||||
str.substring(startYamlPos + startYamlStr.length, endYamlPos);
|
|
||||||
var map = parseYamlText(yamlText);
|
|
||||||
var body = str.substring(0, startYamlPos);
|
|
||||||
|
|
||||||
reverse = true;
|
|
||||||
return MdYamlDoc(body: body, props: map);
|
|
||||||
}
|
|
||||||
|
|
||||||
return MdYamlDoc(body: str);
|
return MdYamlDoc(body: str);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,16 +83,9 @@ class MarkdownYAMLCodec {
|
|||||||
return note.body;
|
return note.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
var str = "";
|
var str = toYamlHeader(note.props);
|
||||||
if (reverse) {
|
|
||||||
str += note.body.trimRight();
|
|
||||||
str += '\n\n';
|
|
||||||
str += toYamlHeader(note.props);
|
|
||||||
} else {
|
|
||||||
str += toYamlHeader(note.props);
|
|
||||||
str += '\n';
|
str += '\n';
|
||||||
str += note.body;
|
str += note.body;
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -188,30 +188,6 @@ foo: bar
|
|||||||
expect(actualStr, str + '\n');
|
expect(actualStr, str + '\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('YAML at the end of the doc', () {
|
|
||||||
var str = """Alright.
|
|
||||||
|
|
||||||
---
|
|
||||||
type: Journal
|
|
||||||
created: 2017-02-15T22:41:19+01:00
|
|
||||||
foo: bar
|
|
||||||
---
|
|
||||||
""";
|
|
||||||
|
|
||||||
var serializer = MarkdownYAMLCodec(reverse: true);
|
|
||||||
var doc = serializer.decode(str);
|
|
||||||
expect(doc.body, "Alright.\n\n");
|
|
||||||
expect(doc.props.length, 3);
|
|
||||||
|
|
||||||
var actualStr = serializer.encode(doc);
|
|
||||||
|
|
||||||
expect(actualStr, str);
|
|
||||||
});
|
|
||||||
|
|
||||||
// FIXME: Add another test for yaml header at the bottom without a newline
|
|
||||||
// FIXME: Add another test for yaml header at the bottom with lots of new lines after
|
|
||||||
// FIXME: Add another test for yaml header at the bottom with lots of new lines with spaces after
|
|
||||||
|
|
||||||
test('Should not have any YamlMaps', () {
|
test('Should not have any YamlMaps', () {
|
||||||
// YamlMaps cannot be sent over an isolate
|
// YamlMaps cannot be sent over an isolate
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user