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

Post can't handle metadata dict with 'content' key #113

Closed razvanvilceanu closed 9 months ago

razvanvilceanu commented 9 months ago

Hi,

I am using frontmatter in a python script to convert MD files to XML and I found this issue where I have an MD file having a field called 'content' for which, creating a Post instance doesn't work, returning the following exception:

  File "C:\work\projects\xxx\venv\Lib\site-packages\frontmatter\__init__.py", line 168, in loads
    return Post(content, handler, **metadata)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Post.__init__() got multiple values for argument 'content'

An easy fix for this would be to add a condition to replace the name of the key in metadata, if a content key is already existing:

        if 'content' in metadata.keys():
            metadata['metadata_content'] = metadata.pop('content')

In my case, I added it in the parse function, line 85.

Can this be implemented in the following release of the package?

eyeseast commented 9 months ago

Duplicate of #96