Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support blank lines in YAML/TOML metadata (part of issue #2801) #2827

Merged
merged 2 commits into from Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -11,6 +11,7 @@ Features
Bugfixes
--------

* Support empty lines in YAML/TOML metadata (Part of issue #2801)
* Tests run on macOS.

New in v7.8.7
Expand Down
7 changes: 6 additions & 1 deletion nikola/plugin_categories.py
Expand Up @@ -338,7 +338,12 @@ def split_metadata(self, data):
This splits in the first empty line that is NOT at the beginning
of the document.
"""
split_result = re.split('(\n\n|\r\n\r\n)', data.lstrip(), maxsplit=1)
if data.startswith('---'): # YAML metadata
split_result = re.split('(---\n\n|----\r\n\r\n)', data.lstrip(), maxsplit=1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have four dashes before the Windows newlines. I guess that's one too many.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: isn't it better to split along \n\n---\n\n (for Unix-style newlines) instead of ---\n\n? Otherwise, a line ending with --- will also suffice for a split (which is probably not what you want), as opposed to a line containing only ---.

Copy link
Member Author

@ralsina ralsina Jun 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good points. I think you mean "\n---\n\n" but yes :-)

elif data.startswith('+++'): # TOML metadata
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:
return '', split_result[0]
# ['metadata', '\n\n', 'post content']
Expand Down