python-frontmatter
python-frontmatter copied to clipboard
How to write metadata with indentation?
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