From ada656c675f06effd844c05207f2a8683e099c1d Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Wed, 19 Aug 2020 11:31:16 +0200 Subject: [PATCH] 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 --- lib/core/note_serializer.dart | 1 + test/note_test.dart | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/core/note_serializer.dart b/lib/core/note_serializer.dart index d7e8f779..7b5562dc 100644 --- a/lib/core/note_serializer.dart +++ b/lib/core/note_serializer.dart @@ -148,6 +148,7 @@ class NoteSerializer implements NoteSerializerInterface { note.title = emojiParser.emojify(title); propsUsed.add(settings.titleKey); + settings.saveTitleAsH1 = false; } else { var startsWithH1 = false; for (var line in LineSplitter.split(note.body)) { diff --git a/test/note_test.dart b/test/note_test.dart index 16e71c1d..f83684a7 100644 --- a/test/note_test.dart +++ b/test/note_test.dart @@ -217,5 +217,39 @@ Gee expect(txtNote.title.isEmpty, true); 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); + }); }); }