Skip to content

Commit

Permalink
Fix two grave and one interop bug in TOML/YAML meta handling
Browse files Browse the repository at this point in the history
1. toml.load wants a file handle, toml.loads wants a string
2. `+` has special meaning in regular expressions
3. Require one linebreak after TOML/YAML (as Jekyll does)
  • Loading branch information
Kwpolska committed Jun 11, 2017
1 parent 4e6c32c commit 39fe4da
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions nikola/plugin_categories.py
Expand Up @@ -339,9 +339,9 @@ def split_metadata(self, data):
of the document.
"""
if data.startswith('---'): # YAML metadata
split_result = re.split('(\n---\n\n|\r\n---\r\n\r\n)', data.lstrip(), maxsplit=1)
split_result = re.split('(\n---\n|\r\n---\r\n)', data.lstrip(), maxsplit=1)
elif data.startswith('+++'): # TOML metadata
split_result = re.split('(\n+++\n\n|\r\n+++\r\n\r\n)', data.lstrip(), maxsplit=1)
split_result = re.split('(\n\\+\\+\\+\n|\r\n\\+\\+\\+\r\n)', data.lstrip(), maxsplit=1)
else:
split_result = re.split('(\n\n|\r\n\r\n)', data.lstrip(), maxsplit=1)
if len(split_result) == 1:
Expand Down
2 changes: 1 addition & 1 deletion nikola/post.py
Expand Up @@ -1041,7 +1041,7 @@ def _get_metadata_from_file(meta_data, config=None):
utils.req_missing('toml', 'use TOML metadata', optional=True)
raise ValueError('Error parsing metadata')
idx = meta_data.index('+++', 1)
meta = toml.load('\n'.join(meta_data[1:idx]))
meta = toml.loads('\n'.join(meta_data[1:idx]))
# Map metadata from other platforms to names Nikola expects (Issue #2817)
map_metadata(meta, 'toml', config)
return meta
Expand Down

0 comments on commit 39fe4da

Please sign in to comment.