Skip to content

How to write metadata with indentation? #115

@Guts

Description

@Guts

Thanks for this useful package!

I'm using it to homogenize YAML frontmatter through thousands of Markdown files but I can't figure out how to keep the source file indentation (to 4):

Input Markdown:

---
date: 2023-05-12
title: Sample
tags:
    - test
    - sample
---

# Title 1

Script:

[...]
# write new version
with md_filepath.open(mode="w", encoding="UTF-8") as out_file:
    # frontmatter.dump(content, out_file) # not working, using workaround
    out_file.write(
        frontmatter.dumps(content, sort_keys=False, **{"indent": 4})
    )

Output Markdown:

See tags values

---
processed: true
date: 2023-05-12
title: Sample
tags:
- test
- sample
---

# Title 1

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