Skip to content

Support multi-document YAML without forcing explicit start markers or removing separators #307

@sindrebenjaminremman

Description

@sindrebenjaminremman

Description

We're struggling to use yamlfix when there are multiple YAML documents in a single file, but we don't want to enforce an explicit start marker at the top.

Example scenario:

book_library:
  - title: Why we sleep
    author: Matthew Walker
  - title: Harry Potter and the Methods of Rationality
    author: Eliezer Yudkowsky
---
book_library:
  - title: Why We Matter
    author: Emeka Anyaoku
  - title: Harry Potter and the Goblet of Fire
    author: J.K. Rowling
---
book_library:
  - title: No Sleep Till Brooklyn
    author: Beastie Boys
  - title: Harry Potter and the Half-Blood Prince
    author: J.K. Rowling

Current behavior:

  • With explicit_start = true, yamlfix adds --- at the start and end of the file, which we do not want.
---
book_library:
  - title: Why we sleep
    author: Matthew Walker
  - title: Harry Potter and the Methods of Rationality
    author: Eliezer Yudkowsky
---
book_library:
  - title: Why We Matter
    author: Emeka Anyaoku
  - title: Harry Potter and the Goblet of Fire
    author: J.K. Rowling
---
book_library:
  - title: No Sleep Till Brooklyn
    author: Beastie Boys
  - title: Harry Potter and the Half-Blood Prince
    author: J.K. Rowling
  • With explicit_start = false, all --- markers are removed, causing key duplication and breaking multi-document structure.
book_library:
  - title: Why we sleep
    author: Matthew Walker
  - title: Harry Potter and the Methods of Rationality
    author: Eliezer Yudkowsky
book_library:
  - title: Why We Matter
    author: Emeka Anyaoku
  - title: Harry Potter and the Goblet of Fire
    author: J.K. Rowling
book_library:
  - title: No Sleep Till Brooklyn
    author: Beastie Boys
  - title: Harry Potter and the Half-Blood Prince
    author: J.K. Rowling

Expected Behavior

Provide an option to:

  • Preserve existing --- markers between documents.
  • Avoid adding --- at the end of the file.
  • Optionally allow a single --- at the start (front matter) only if requested.

Possible Solution

Introduce a new configuration option, for example:

# Preserve multi-document separators but do not add trailing markers
document_markers = "preserve"   # keeps existing '---' between documents, no extra at end

# Or allow explicit modes:
document_markers = "front_matter_only"  # adds one '---' at start, preserves others
document_markers = "remove_all"         # removes all markers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions