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

Colon character not supported #70

Closed raspbeguy closed 3 years ago

raspbeguy commented 3 years ago

Hello,

When I ask python-frontmatter to parse a frontmatter with a colon : in the value, it throws an error.

Example:

---
title: foo : bar
author: somebody
date: 2020
template: post
tags: nothing
---

Hello

This throws the following error:

Traceback (most recent call last):
  File "./geminer.py", line 28, in <module>
    meta = frontmatter.parse(mdtext)[0]
  File "/usr/lib/python3.8/site-packages/frontmatter/__init__.py", line 87, in parse
    fm = handler.load(fm)
  File "/usr/lib/python3.8/site-packages/frontmatter/default_handlers.py", line 213, in load
    return yaml.load(fm, **kwargs)
  File "/usr/lib/python3.8/site-packages/yaml/__init__.py", line 114, in load
    return loader.get_single_data()
  File "/usr/lib/python3.8/site-packages/yaml/constructor.py", line 49, in get_single_data
    node = self.get_single_node()
  File "ext/_yaml.pyx", line 707, in _yaml.CParser.get_single_node
  File "ext/_yaml.pyx", line 725, in _yaml.CParser._compose_document
  File "ext/_yaml.pyx", line 776, in _yaml.CParser._compose_node
  File "ext/_yaml.pyx", line 892, in _yaml.CParser._compose_mapping_node
  File "ext/_yaml.pyx", line 905, in _yaml.CParser._parse_next_event
yaml.scanner.ScannerError: mapping values are not allowed in this context
  in "<unicode string>", line 2, column 12

And yet the syntax with the colon is valid in regular CMS, like PicoCMS.

When I remove the colon, it works as expected.

eyeseast commented 3 years ago

This is probably an issue with YAML not knowing whether it's a string or a new key. Try quoting the value and see if that fixes it.

raspbeguy commented 3 years ago

@eyeseast it works when quoting, but like I said, it works with regular CMS, and I don't wish to change all my content.

eyeseast commented 3 years ago

I'm not sure what to tell you here. I think your choices are to use quotes or try something else.