Do not write the title as h1 if it is in the yaml header

In general, we try to follow the conventions in the note parsed over
whatever the default config.

Related to #214
This commit is contained in:
Vishesh Handa
2020-08-19 11:31:16 +02:00
parent 32f032204f
commit ada656c675
2 changed files with 35 additions and 0 deletions

View File

@ -148,6 +148,7 @@ class NoteSerializer implements NoteSerializerInterface {
note.title = emojiParser.emojify(title); note.title = emojiParser.emojify(title);
propsUsed.add(settings.titleKey); propsUsed.add(settings.titleKey);
settings.saveTitleAsH1 = false;
} else { } else {
var startsWithH1 = false; var startsWithH1 = false;
for (var line in LineSplitter.split(note.body)) { for (var line in LineSplitter.split(note.body)) {

View File

@ -217,5 +217,39 @@ Gee
expect(txtNote.title.isEmpty, true); expect(txtNote.title.isEmpty, true);
expect(txtNote.body, content); expect(txtNote.body, content);
}); });
test('Yaml is not touched with yaml disabled', () async {
var content = """---
layout: post
title: Blogging
date: 2020-08-12T13:53:52+02:00
categories: can-learn-foo
permalink: /:categories
---
Blah blah""";
var notePath = p.join(tempDir.path, "note63345.md");
await File(notePath).writeAsString(content);
var parentFolder = NotesFolderFS(null, tempDir.path);
var note = Note(parentFolder, notePath);
await note.load();
note.body = "Howdy";
await note.save();
var actualContent = await File(notePath).readAsString();
var expectedContent = """---
layout: post
title: Blogging
date: 2020-08-12T13:53:52+02:00
categories: can-learn-foo
permalink: /:categories
---
Howdy""";
expect(actualContent, expectedContent);
});
}); });
} }