Setting: Note metadata change subtitle

This commit is contained in:
Vishesh Handa
2020-07-29 15:13:24 +02:00
parent 41447027f2
commit 417f0414f2
3 changed files with 35 additions and 15 deletions

View File

@ -39,7 +39,7 @@ settings:
subtitle: Configure where your notes are synced
noteMetaData:
title: Note Metadata Settings
subtitle: Configure how the YAML Metadata is saved
subtitle: Configure how the Note Metadata is saved
text: Every note has some metadata which is stored in a YAML Header as follows -
enableHeader: Enable YAML Header
modified: Modified Field

View File

@ -50,6 +50,7 @@ class NoteSerializer implements NoteSerializerInterface {
if (settings.saveTitleAsH1) {
if (title.isNotEmpty) {
data.body = '# $title\n\n${data.body}';
data.props.remove(settings.titleKey);
}
} else {
if (title.isNotEmpty) {
@ -102,25 +103,25 @@ class NoteSerializer implements NoteSerializerInterface {
//
// Title parsing
//
if (settings.saveTitleAsH1) {
if (note.body.startsWith('#')) {
var titleEndIndex = note.body.indexOf('\n');
if (titleEndIndex == -1 || titleEndIndex == note.body.length) {
note.title = note.body.substring(1).trim();
note.body = "";
} else {
note.title = note.body.substring(1, titleEndIndex).trim();
note.body = note.body.substring(titleEndIndex + 1).trim();
}
if (data.props.containsKey(settings.titleKey)) {
var title = data.props[settings.titleKey]?.toString() ?? "";
note.title = emojiParser.emojify(title);
} else if (note.body.startsWith('#')) {
var titleEndIndex = note.body.indexOf('\n');
if (titleEndIndex == -1 || titleEndIndex == note.body.length) {
note.title = note.body.substring(1).trim();
note.body = "";
} else {
note.title = note.body.substring(1, titleEndIndex).trim();
note.body = note.body.substring(titleEndIndex + 1).trim();
}
/*
for (var line in LineSplitter.split(note.body)) {
if (note.title.isEmpty && line.trim().isEmpty) {
continue;
}
}
} else {
var title = data.props[settings.titleKey]?.toString() ?? "";
note.title = emojiParser.emojify(title);
*/
}
var type = data.props[settings.typeKey];

View File

@ -30,7 +30,7 @@ void main() {
expect(doc.props['title'].toString(), "I :heart: you");
});
test('Test Title', () {
test('Test Title Serialization', () {
var props = <String, dynamic>{};
var doc = MdYamlDoc("# Why not :coffee:?\n\nI :heart: you", props);
@ -50,5 +50,24 @@ void main() {
expect(doc.body, "# I :heart: you\n\nWhy not :coffee:?");
expect(doc.props.length, 0);
});
test('Test Old Title Serialization', () {
var props = LinkedHashMap<String, dynamic>.from(
<String, dynamic>{"title": "Why not :coffee:?"});
var doc = MdYamlDoc("I :heart: you", props);
var serializer = NoteSerializer();
serializer.settings.saveTitleAsH1 = true;
var note = Note(null, "file-path-not-important");
serializer.decode(doc, note);
expect(note.body, "I ❤️ you");
expect(note.title, "Why not ☕?");
serializer.encode(note, doc);
expect(doc.body, "# Why not :coffee:?\n\nI :heart: you");
expect(doc.props.length, 0);
});
});
}