Skip to content

Commit

Permalink
Merge pull request #2832 from getnikola/fix-toml-meta
Browse files Browse the repository at this point in the history
Fix two grave and one interop bug in TOML/YAML meta handling
  • Loading branch information
Kwpolska authored Jun 12, 2017
2 parents 4b23490 + b54a1a4 commit 8f8a215
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Features
Bugfixes
--------

* Fix two grave bugs in TOML metadata
* Require just one line break after TOML/YAML metadata
* Add alt attribute to images in galleries in base theme (Part of issue #2777)
* Support empty lines in YAML/TOML metadata (Part of issue #2801)
* Tests run on macOS.
Expand Down
6 changes: 3 additions & 3 deletions nikola/plugin_categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,12 +336,12 @@ def split_metadata(self, data):
"""Split data from metadata in the raw post content.
This splits in the first empty line that is NOT at the beginning
of the document.
of the document, or after YAML/TOML metadata without an empty line.
"""
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
Original file line number Diff line number Diff line change
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 8f8a215

Please sign in to comment.