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

Jekyll fails to detect front matter on files with windows line endings #3304

Closed
benbalter opened this issue Jan 13, 2015 · 6 comments
Closed
Labels
frozen-due-to-age windows Related to the Windows platform

Comments

@benbalter
Copy link
Contributor

Steps to reproduce (hint: line-ending-converter for Atom helps):

  1. Create a new HTML file, adding YAML front matter
  2. Save the file with all windows line endings

Expected:

Front matter is detected, file is read in

Actual:

File is treated as static HTML, front matter is converted raw.

Originally, I suspected this was my fault, introduced in #2211, but it appears it's \r safe. Perhaps it needs (\r|\n|\r\n)?

@benbalter benbalter added Bug windows Related to the Windows platform labels Jan 13, 2015
@parkr
Copy link
Member

parkr commented Jan 13, 2015

Do you have a test file? We'd need to know what the status of the special characters is.

@parkr
Copy link
Member

parkr commented Jan 13, 2015

For reference, here's the presently-used Utils.has_yaml_header? function:

    def has_yaml_header?(file)
      !!(File.open(file, 'rb') { |f| f.read(5) } =~ /\A---\r?\n/)
    end

It's \r-safe. It should always have \n. LF = \n, CR = \r\n IIRC.

@envygeeks
Copy link
Contributor

CR = \r and CR+LF (Windows) is \r\n but that said, messengers use CR (Pidgin, Empathy, Adium - which all use libpurple) and unless your text editor adjusts the line endings it will remain CR, and for a text editor to adjust that without user intervention or user explicit automatic intervention is bad IMO but also this is a sign of a much bigger problem that shouldn't need exist.

Jekyll should normalize in and customize out:

str1 = "hello\r"
str2 = "hello\r\n"
str1.encode(str1.encoding, :universal_newline => true) # => "hello\n"
str2.encode(str2.encoding, :universal_newline => true) # => "hello\n"

Then on the way out do the same thing from an opt that Jekyll accepts, or if you detect Windows then default to :crlf_newline => true the craziness of should not need to be hardcoded into the logic 😉 because it should be normalized and assumed internally then re-normalized and customized on the way out.

@benbalter
Copy link
Contributor Author

I'm with @envygeeks that we should normalize, if possible (for our own sanity, and for our users' sanity).

https://github.com/dweinberger/newclues/blob/master/newclues.html is an example file (with \rs), if you add front matter. FWIW, GitHub doesn't properly detect the line breaks for numbering purposes.

@parkr
Copy link
Member

parkr commented Jan 14, 2015

Jekyll should normalize in and customize out

I'm good with this. I'll work on this next.

@parkr
Copy link
Member

parkr commented Dec 13, 2015

I believe this has been fixed in Jekyll 3. THanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
frozen-due-to-age windows Related to the Windows platform
Projects
None yet
Development

No branches or pull requests

4 participants