eyeseast / python-frontmatter

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

Quotes strings with incorrect syntax #97

Closed willfaught closed 2 years ago

willfaught commented 2 years ago

Say a frontmatter entry is this:

title: "MacOS: It's Time To Take The Next Step"

This will be serialized as title: 'MacOS: It's Time To Take The Next Step', which isn't valid.

eyeseast commented 2 years ago

Looks like it's an issue with PyYAML:

>>> import yaml
>>> fm = '''title: "MacOS: It's Time To Take The Next Step"'''
>>> d = yaml.load(fm, Loader=yaml.SafeLoader)
>>> d
{'title': "MacOS: It's Time To Take The Next Step"}

# this is what frontmatter.dumps does
>>> yaml.dump(d, Dumper=yaml.SafeDumper, default_flow_style=False, allow_unicode=True)
"title: 'MacOS: It''s Time To Take The Next Step'\n"

Maybe something about SafeDumper?

willfaught commented 2 years ago

I think this was my mistake. I think it serialized using the '' escape for apostrophes, and I later replaced '' with ', which then made the YAML invalid. Sorry for the confusion, and thanks for looking into it.