It seems that for the strings longer than 79 characters, underlying YAML serializer inserts line break
So for line of length 80+ the following code
const string80 = 'a'.repeat(78) + ' b';
await app.fileManager.processFrontMatter(app.workspace.getActiveFile(), (frontMatter) => { frontMatter.key = string80; });
Makes
---
key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
b
---
While for the string with 79- length, the line break is not created
const string79 = 'a'.repeat(77) + ' b';
await app.fileManager.processFrontMatter(app.workspace.getActiveFile(), (frontMatter) => { frontMatter.key = string79; });
makes
---
key: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa b
---
While in both cases the generated YAML is valid, sometimes such line breaks are undesirable.
I have a suspicion that Obsidian internally uses js-yaml library with its dump
method to serialize objects to YAML strings.
This dump
method has lineWidth
option which is by default is 80
.
If you set it to -1
, the undesired line break disappears.
I encourage Obsidian developers to think how to give us more control over this YAML serialization.
Thus we can configure
- if we want line breaks or not
- if we want to use single or double quotes
- if we want arrays to be inline
['a', 'b' ,'c']
or multi-line
- a
- b
- c
etc