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

Do not strip whitespaces and newlines when separating content from metadata #463

Merged
merged 1 commit into from Aug 16, 2014

Conversation

@gpakosz
Copy link
Member

@gpakosz gpakosz commented Jul 19, 2014

When parsing items and separating content from metadata, Nanoc strips the content: https://github.com/nanoc/nanoc/blob/3.7.1/lib/nanoc/data_sources/filesystem.rb#L271

This is bogus and prevents the following Markdown from being correctly compiled:

----
title: I start with a code block
----
    this is a code block
    this is a code block

Calling #strip removes the leading spaces and breaks the code block.

@coveralls
Copy link

@coveralls coveralls commented Jul 19, 2014

Coverage Status

Coverage decreased (-0.14%) when pulling b468474 on gpakosz:fix-metadata-parsing into 613f6ec on nanoc:release-3.7.x.

Loading

@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Jul 19, 2014

Can you add a test for this?

Loading

@gpakosz
Copy link
Member Author

@gpakosz gpakosz commented Jul 20, 2014

So in the end I decided to only strip leading and trailing new lines. Because e.g. in Markdown, both leading spaces and trailing spaces have a meaning.

And this doesn't require to change existing tests.

Loading

@gpakosz gpakosz changed the title Do not left strip content when after having parsed metadata Strip only new-lines when separating content from metadata Jul 20, 2014
@gpakosz gpakosz changed the title Strip only new-lines when separating content from metadata Strip only new lines when separating content from metadata Jul 20, 2014
@gpakosz
Copy link
Member Author

@gpakosz gpakosz commented Jul 20, 2014

Now I'm wondering, maybe it's better to not strip anything at all, and leave everything after the metadata block intact? What do you think?

Loading

@FredyFreshFirm
Copy link

@FredyFreshFirm FredyFreshFirm commented Jul 21, 2014

Strip
20. juli 2014 14:48 skrev "Gregory Pakosz" notifications@github.com
følgende:

Now I'm wondering, maybe it's better to not strip anything at all, and
leave everything after the metadata block intact? What do you think?


Reply to this email directly or view it on GitHub
#463 (comment).

Loading

@ddfreyne ddfreyne added the bug label Aug 9, 2014
@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Aug 9, 2014

I feel that not stripping anything at all is the right choice here.

Loading

@gpakosz
Copy link
Member Author

@gpakosz gpakosz commented Aug 9, 2014

So yeah I pushed a version that doesn't strip. But that breaks many tests.

So I promptly reverted that branch to the version that strips only leading and ending new lines: this is a conservative approach.

Loading

@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Aug 9, 2014

I’m OK with stripping leading empty lines, but I’m not sure about trailing ones. It is common and good practice to end a file with a newline. We should be able to get away with just stripping leading empty lines, right?

Loading

@gpakosz
Copy link
Member Author

@gpakosz gpakosz commented Aug 9, 2014

Well existing tests assume trailing newlines are stripped. I'm ok with not stripping anything at all. That means changing all tests.

Loading

@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Aug 9, 2014

+1 with stripping trailing newlines. If somebody complains, we can always fix it later :)

Loading

@gpakosz
Copy link
Member Author

@gpakosz gpakosz commented Aug 9, 2014

Ok by now nothing is stripped. By now content contains leading and trailing spaces / new lines.

Loading

@@ -268,7 +268,7 @@ def parse(content_filename, meta_filename, kind)
rescue Exception => e
raise "Could not parse YAML for #{content_filename}: #{e.message}"
end
content = pieces[4..-1].join.strip
content = pieces[4..-1].join
Copy link
Member

@ddfreyne ddfreyne Aug 9, 2014

Choose a reason for hiding this comment

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

I like to have a blank line between the metadata section and the content, like this:

---
title: "Hello"
---

content goes here

What about calling .sub(/\A[\r\n]/, '') on the content (instead of.strip` originally)? That would allow the empty line between metadata and content and it’d still be stripped (it’d be the only thing that is stripped).

Loading

By now, content contains leading and trailing spaces / new lines
@gpakosz
Copy link
Member Author

@gpakosz gpakosz commented Aug 9, 2014

Well imho, what comes after "---" is the content. If you like to have a blank line for visual reasons, then that blank line is part of the content. Does it harm the pipeline to keep it? In the end HTML doesn't care.

So maybe it's better to consider it's part of content? Otherwise the line is blurry.

Loading

@bobthecow
Copy link
Member

@bobthecow bobthecow commented Aug 9, 2014

In YAML's opinion it's part of the content, too :)

Loading

@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Aug 9, 2014

+1 for removing the blank line as well.

Loading

@ddfreyne
Copy link
Member

@ddfreyne ddfreyne commented Aug 15, 2014

@gpakosz Is this ready to go?

Loading

@gpakosz
Copy link
Member Author

@gpakosz gpakosz commented Aug 15, 2014

I believe it is.

Remember FilesystemUnified#create_object doesn't write a blank line before writing content anymore. Do you want the create-item to be adjusted accordingly to keep your "I like to have a blank line between the metadata section and the content" preference?

Loading

ddfreyne added a commit that referenced this issue Aug 16, 2014
Strip only new lines when separating content from metadata
@ddfreyne ddfreyne merged commit a3b7f76 into nanoc:release-3.7.x Aug 16, 2014
1 check passed
Loading
@gpakosz gpakosz changed the title Strip only new lines when separating content from metadata Do not strip whitespaces and newlines when separating content from metadata Aug 17, 2014
ddfreyne added a commit that referenced this issue Aug 17, 2014
@gpakosz gpakosz deleted the fix-metadata-parsing branch Sep 6, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants