Skip to content

Option to preserve frontmatter formatting when patching a single key #24

Closed

Description

@jlfreire

Summary
Patching one frontmatter key re-serialises the whole YAML block. This changes lines that the instruction never targeted. Would you consider an opt-in option, e.g. preserveFrontmatterFormatting, that splices only the target key’s lines and leaves the rest of the block byte-for-byte unchanged?

Observed (via the Local REST API MCP vault_patch)

  1. origin: (empty) becomes origin: null after a patch to a different key.
  2. Creating a key with value: null writes destination: "null", a string rather than an empty value. This looks like a bug regardless of the option.
  3. Template placeholders such as created: {{date:YYYY-MM-DD}} are turned into a nested mapping after a patch to another key. I appreciate this is not plain YAML, but it is common in Obsidian templates.
  4. Comments and quoting style are lost.

Expected (with the option on)
Only the lines of the target key change. If the edit cannot be spliced safely (anchors, aliases, complex flow nodes), fall back to the current behaviour.

Prior art
The Preserve Frontmatter Formatting Obsidian plugin takes this approach, with the same fallback.

Activity

  1. Repository owner locked and limited conversation to collaborators on Nov 10, 2026
  2. converted this issue into a discussion #25 on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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