Skip to content
Permalink
Browse files
Fix two grave and one interop bug in TOML/YAML meta handling
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 39fe4da59e3262f8c82012532d964cd8677f2338
Showing with 3 additions and 3 deletions.
  1. +2 −2 nikola/plugin_categories.py
  2. +1 −1 nikola/post.py
@@ -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:
@@ -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

0 comments on commit 39fe4da

Please sign in to comment.