0

I make my notes in markdown and use yamle metadata blocks at the top of the file. I frequently use pandoc in order to format my notefiles. Unfortunately, it seems to me that in this process lists are not aligned correctly - at least with respect to my understanding of yaml. Example:

Before:

---
tags:
    - capitalism
    - democracy
    - 'post-2008'
---

# Nach der 2008/2009 Wirtschaftskrise werden westliche Demokratien zusehends autoritär

Generell hegt die Linke die These das Kapitalismus und Demokratie nicht
zwingend zusammen gehören (siehe [Demokratie Ergebnis von
Arbeiterkämpfen](Demokratisierung_ist_Ergebnis_Proteste_mit_Arbeiterklasse.md)).

After:

---
tags:
- capitalism
- democracy
- 'post-2008'
---

# Nach der 2008/2009 Wirtschaftskrise werden westliche Demokratien zusehends autoritär

Generell hegt die Linke die These das Kapitalismus und Demokratie nicht
zwingend zusammen gehören (siehe [Demokratie Ergebnis von
Arbeiterkämpfen](Demokratisierung_ist_Ergebnis_Proteste_mit_Arbeiterklasse.md)).

The alignment of the list entries in the yaml metadata block completely disappear.

The pandoc command I use ist:

pandoc --standalone \
       --atx-headers \
       -f markdown-auto_identifiers+yaml_metadata_block \
       -t markdown-simple_tables-multiline_tables-grid_tables-auto_identifiers-fenced_code_attributes+yaml_metadata_block
Cutú Chiqueño
  • 855
  • 1
  • 10
  • 24

1 Answers1

2

The output YAML is still valid since the YAML spec says that

The “-”, “?” and “:” characters used to denote block collection entries are perceived by people to be part of the indentation. This is handled on a case-by-case basis by the relevant productions.

Since - is parsed as part of the indentation, the items in your list are more indented than the parent key tags:, which makes this valid YAML and equivalent to your input.

Your YAML looks different because pandoc parses it and then emits it again. YAML is not round-tripping and therefore cannot perfectly preserve format. For details, see this question.

flyx
  • 35,506
  • 7
  • 89
  • 126