eyeseast / python-frontmatter

Parse and manage posts with YAML (or other) frontmatter
http://python-frontmatter.rtfd.io
MIT License
333 stars 42 forks source link

retrieve just the original frontmatter in yaml #86

Closed nsheff closed 3 years ago

nsheff commented 3 years ago

I know I can do frontmatter.dumps(post) to get the original frontmatter+md source back as a string -- but I propose an additional hook to get just the original yaml frontmatter source back -- right now you if you split them, you can only get it as a dict.

eyeseast commented 3 years ago

In this case, I'd recommend using the underlying library directly. If you have YAML frontmatter, you can use PyYAML:

import yaml

yaml.dump(post.metadata)

That's most of what's happening under the hood: https://github.com/eyeseast/python-frontmatter/blob/master/frontmatter/default_handlers.py#L240-L249