Calling processFrontMatter
will destroy all previous formatting, and most YAML features/syntax. As you will see from the expected vs actual output, the behavior is quite odd.
Steps to reproduce
- Modify the sample’s ‘sample-editor-command’ code in the onload method here to the content below
this.addCommand({
id: 'sample-editor-command',
name: 'Sample editor command',
editorCallback: (editor: Editor, view: MarkdownView) => {
console.log(editor.getSelection());
editor.replaceSelection('Sample Editor Command');
let file = this.app.workspace.getActiveFile();
this.app.fileManager.processFrontMatter(file, (frontmatter) => {
console.log('this is the frontmatter', frontmatter)
})
}
});
- Create a file with the following frontmatter content
---
description: 'course; subject, note'
id: "deadbeef-123-$$"
date: !!timestamp 2022-01-25
date2: 2022-01-25
# a comment
forced-string: !!str "i should have bookend quotes"
status: !!null Null
nameArary: [six, seven, eight, nine, ten]
nameArrayQuoted: ["six", "seven", "eight", "nine", "ten"]
nameBlockStyleQuoted:
- "six"
- "seven"
- "eight"
- "nine"
a: 123 # an integer
b: "123" # a string, disambiguated by quotes
c: 123.0 # a float
d: !!float 123 # also a float via explicit data type prefixed by (!!)
e: !!str 123 # a string, disambiguated by explicit type
f: !!str Yes # a string via explicit type
g: Yes # a boolean True (yaml1.1), string "Yes" (yaml1.2)
h: Yes we have No bananas # a string, "Yes" and "No" disambiguated by context.
---
- Run the ‘Sample editor command’ command
Did you follow the troubleshooting guide? [Y/N]
Yes
Expected result
Front matter is not modified
---
description: 'course; subject, note'
id: "deadbeef-123-$$"
date: !!timestamp 2022-01-25
date2: 2022-01-25
# a comment
forced-string: !!str "i should have bookend quotes"
status: !!null Null
nameArary: [six, seven, eight, nine, ten]
nameArrayQuoted: ["six", "seven", "eight", "nine", "ten"]
nameBlockStyleQuoted:
- "six"
- "seven"
- "eight"
- "nine"
a: 123 # an integer
b: "123" # a string, disambiguated by quotes
c: 123.0 # a float
d: !!float 123 # also a float via explicit data type prefixed by (!!)
e: !!str 123 # a string, disambiguated by explicit type
f: !!str Yes # a string via explicit type
g: Yes # a boolean True (yaml1.1), string "Yes" (yaml1.2)
h: Yes we have No bananas # a string, "Yes" and "No" disambiguated by context.
---
Actual result
A string’s quotes can be removed, newlines are removed, comments are removed, types are removed, timestamp types are modified, and inline strctures (arrays) are converted to block style.
---
description: course; subject, note
id: deadbeef-123-$$
date: 2022-01-25T00:00:00.000Z
date2: 2022-01-25
forced-string: i should have bookend quotes
status: null
nameArary:
- six
- seven
- eight
- nine
- ten
nameArrayQuoted:
- six
- seven
- eight
- nine
- ten
nameBlockStyleQuoted:
- six
- seven
- eight
- nine
a: 123
b: "123"
c: 123
d: "123"
e: "123"
f: Yes
g: Yes
h: Yes we have No bananas
---
Environment
SYSTEM INFO:
Obsidian version: v1.3.7
Installer version: v1.1.9
Operating system: Darwin Kernel Version 22.6.0: Wed Jul 5 22:22:05 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T6000 22.6.0
Login status: not logged in
Insider build toggle: off
Live preview: on
Legacy editor: off
Base theme: dark
Community theme: none
Snippets enabled: 0
Restricted mode: off
Plugins installed: 1
Plugins enabled: 1
1: Sample Plugin v1.0.0
Additional information
Possibly related: `processFrontMatter` creates undesired line break for long strings