YAML frontmatter formatting

Hello, as key parts of my notes often end up as a YAML set of key:value, I am looking for a way to make this look better. For example:

Instead of:
key1:: value1
key_number_2:: value2

I would rather see:
key1:: value1
key_number_2:: value2

Or even:
key1:: value1
key_number_2:: value2

Is this possible?

I see literally zero difference between your three examples.

If the difference was using spaces, you may need to edit (or reply) using non-breaking spaces (“nbsp;” preceded by an “&”) to preserve the differences.

Minor word of warning: whitespace/indentation is significant in YAML (similar to Python and Nim) – you can use spaces to line up values, but spaces at the beginning of a line can change a key to a subkey …

There were spaces in my draft! - and I just found out that I can put key:value in a table:

Key|Value
---|-----
URL:: | http://www.google.com
Id:: | MyId
Pw:: | MyPW

… rendered as:

image

…and this is how the dataview table looks like:

I just cannot get rid of the pipes.

I got rid of the pipes in the dataview wih substring(value,2):

…unless there is a more elegant solution?

I think this plugin would meet your criteria. but this is only for YAML. it doesn’t affect inline key:: value. if u want to use that, perhaps use it in this manner. if u want to really align, then some css might work

[keyalpha:: value first]
[keybeta:: value second one]

image

Thank you for your answer. However this plugin does not seem to do anything, apart from hiding the “::”. No alignment whatsoever… Should I post a feature request? Again the idea is simply to improve the look of a note, the content of which is essentially a list of key:value sets.

The keys with double colons (::) aren’t YAML — that’s DataView’s syntax.

1 Like

You are certainly right but… If I do not type a double colon after the key, the value does not appear in the dataview table :

You need to put 3 hyphens on the lines before and after it (and the whole thing together starts on the first line of the note):

---
key1: value1
key_number_2: value2
---

That’s a YAML frontmatter block, and its contents should appear in DataView tables.

(Obviously you can use DataView syntax instead if you prefer.)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.