diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0b3779e --- /dev/null +++ b/.editorconfig @@ -0,0 +1,5 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..37a3380 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# force LF on checkout to avoid rustfmt messing up the EOL +* text eol=lf diff --git a/Cargo.lock b/Cargo.lock index 9107fd1..7e5dc98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -230,6 +230,7 @@ dependencies = [ "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "liquid 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "normalize-line-endings 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "notify 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "pulldown-cmark 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -658,6 +659,11 @@ dependencies = [ "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "normalize-line-endings" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "notify" version = "4.0.3" @@ -1317,6 +1323,7 @@ dependencies = [ "checksum miow 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3e690c5df6b2f60acd45d56378981e827ff8295562fc8d34f573deb267a59cd1" "checksum net2 0.2.31 (registry+https://github.com/rust-lang/crates.io-index)" = "3a80f842784ef6c9a958b68b7516bc7e35883c614004dd94959a4dca1b716c09" "checksum nix 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bfb3ddedaa14746434a02041940495bf11325c22f6d36125d3bdd56090d50a79" +"checksum normalize-line-endings 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2e0a1a39eab95caf4f5556da9289b9e68f0aafac901b2ce80daaf020d3b733a8" "checksum notify 4.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5c3812da3098f210a0bb440f9c008471a031aa4c1de07a264fdd75456c95a4eb" "checksum num 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cc4083e14b542ea3eb9b5f33ff48bd373a92d78687e74f4cc0a30caeb754f0ca" "checksum num-integer 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "d1452e8b06e448a07f0e6ebb0bb1d92b8890eea63288c0b627331d53514d0fba" diff --git a/Cargo.toml b/Cargo.toml index ad9282e..48f5751 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -43,6 +43,7 @@ serde = "1.0" serde_yaml = "0.7" serde_json = "1.0" toml = "0.4.0" +normalize-line-endings = "0.2.2" [dependencies.sass-rs] version = "0.2" diff --git a/src/cobalt_model/files.rs b/src/cobalt_model/files.rs index 6c7428d..4d9cab5 100644 --- a/src/cobalt_model/files.rs +++ b/src/cobalt_model/files.rs @@ -2,11 +2,12 @@ use std::fs; use std::io::Read; use std::io::Write; use std::path; +use std::iter::FromIterator; use ignore::Match; use ignore::gitignore::{Gitignore, GitignoreBuilder}; use walkdir::{WalkDir, DirEntry}; - +use normalize_line_endings::normalized; use error::Result; pub struct FilesBuilder { @@ -189,6 +190,7 @@ pub fn read_file>(path: P) -> Result { let mut file = fs::File::open(path.as_ref())?; let mut text = String::new(); file.read_to_string(&mut text)?; + let text = String::from_iter(normalized(text.chars())); Ok(text) } diff --git a/src/lib.rs b/src/lib.rs index c113091..4621435 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -84,6 +84,8 @@ extern crate lazy_static; #[macro_use] extern crate serde; +extern crate normalize_line_endings; + pub use cobalt::build; pub use error::Error; pub use cobalt_model::Config; diff --git a/src/template.rs b/src/template.rs index 325a5b2..24fd427 100644 --- a/src/template.rs +++ b/src/template.rs @@ -3,7 +3,6 @@ use std::path; use std::result; use liquid; - use error::*; use cobalt_model; use cobalt_model::files; diff --git a/tests/fixtures/excerpts_CRLF/.editorconfig b/tests/fixtures/excerpts_CRLF/.editorconfig new file mode 100644 index 0000000..684818a --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/.editorconfig @@ -0,0 +1,3 @@ +[*] +end_of_line = crlf +insert_final_newline = true diff --git a/tests/fixtures/excerpts_CRLF/.gitattributes b/tests/fixtures/excerpts_CRLF/.gitattributes new file mode 100644 index 0000000..be792cf --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/.gitattributes @@ -0,0 +1,2 @@ +# force tests to keep their Windows EOL +* text eol=crlf diff --git a/tests/fixtures/excerpts_CRLF/_cobalt.yml b/tests/fixtures/excerpts_CRLF/_cobalt.yml new file mode 100644 index 0000000..a1f405e --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/_cobalt.yml @@ -0,0 +1,3 @@ +source: "." +site: + title: cobalt blog diff --git a/tests/fixtures/excerpts_CRLF/_includes/post.liquid b/tests/fixtures/excerpts_CRLF/_includes/post.liquid new file mode 100644 index 0000000..dd52f6d --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/_includes/post.liquid @@ -0,0 +1,6 @@ +
+

{{ page.title }}

+

+ {{ page.content }} +

+
diff --git a/tests/fixtures/excerpts_CRLF/_layouts/default.liquid b/tests/fixtures/excerpts_CRLF/_layouts/default.liquid new file mode 100644 index 0000000..453f4a0 --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/_layouts/default.liquid @@ -0,0 +1,15 @@ + + + + {{ page.title }} + + +
+ {% if page.collection == "posts" %} + {% include 'post.liquid' %} + {% else %} + {{ page.content }} + {% endif %} +
+ + diff --git a/tests/fixtures/excerpts_CRLF/index.liquid b/tests/fixtures/excerpts_CRLF/index.liquid new file mode 100644 index 0000000..bc75f2d --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/index.liquid @@ -0,0 +1,15 @@ +layout: default.liquid +--- +
+

Blog!

+ +
+ {% for post in collections.posts.pages %} +
+

{{post.title}}

+

{{ post.title }}

+ {{ post.excerpt }} +
+ {% endfor %} +
+
diff --git a/tests/fixtures/excerpts_CRLF/posts/post-1.md b/tests/fixtures/excerpts_CRLF/posts/post-1.md new file mode 100644 index 0000000..81d73d6 --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/posts/post-1.md @@ -0,0 +1,9 @@ +layout: default.liquid + +title: First block is an excerpt +published_date: 2016-01-14 21:00:30 -0500 +--- + +# This is our first Post! + +Welcome to the first post ever on cobalt.rs! diff --git a/tests/fixtures/excerpts_CRLF/posts/post-10.md b/tests/fixtures/excerpts_CRLF/posts/post-10.md new file mode 100644 index 0000000..7bd5484 --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/posts/post-10.md @@ -0,0 +1,12 @@ +layout: default.liquid + +title: Reference-style links immediately above first block +published_date: 2017-02-11 04:50:21 -0000 +--- + +[20]: /0 + [21]: /1 + [22]: /2 + [23]: /3 +References are placed immediately above the first paragraph: +[20][] [21][] [22][] [23][] diff --git a/tests/fixtures/excerpts_CRLF/posts/post-11.md b/tests/fixtures/excerpts_CRLF/posts/post-11.md new file mode 100644 index 0000000..385bd43 --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/posts/post-11.md @@ -0,0 +1,16 @@ +layout: default.liquid + +title: Reference-style links immediately below first block do not resolve +published_date: 2017-02-11 04:51:34 -0000 +--- + +References are placed immediately below the first paragraph: +[30][] [31][] [32][] [33][] +[30]: /0 + [31]: /1 + [32]: /2 + [33]: /3 + +Note that this is at it should be, as the markdown implementations I've tried +(including CommonMark) do not render the above links (when the post is rendered +individually). diff --git a/tests/fixtures/excerpts_CRLF/posts/post-12.liquid b/tests/fixtures/excerpts_CRLF/posts/post-12.liquid new file mode 100644 index 0000000..36eda06 --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/posts/post-12.liquid @@ -0,0 +1,14 @@ +layout: default.liquid + +title: Reference-style links in a non-markdown post do not resolve +published_date: 2017-02-11 04:48:11 -0000 +--- + +References are placed below the first paragraph, and are separated from the +first paragraph by a single blank line: +[40][] [41][] [42][] [43][] + +[40]: /0 + [41]: /1 + [42]: /2 + [43]: /3 diff --git a/tests/fixtures/excerpts_CRLF/posts/post-2.md b/tests/fixtures/excerpts_CRLF/posts/post-2.md new file mode 100644 index 0000000..8006d9b --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/posts/post-2.md @@ -0,0 +1,5 @@ +layout: default.liquid + +title: An empty post means an empty excerpt +published_date: 2016-01-14 21:01:30 -0500 +--- diff --git a/tests/fixtures/excerpts_CRLF/posts/post-3.md b/tests/fixtures/excerpts_CRLF/posts/post-3.md new file mode 100644 index 0000000..75306cb --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/posts/post-3.md @@ -0,0 +1,10 @@ +layout: default.liquid + +title: Explicit `excerpt` +published_date: 2016-01-14 21:02:30 -0500 +excerpt: Is in `markdown` +--- + +# This is our third Post! + +Welcome to the third post ever on cobalt.rs! diff --git a/tests/fixtures/excerpts_CRLF/posts/post-4.md b/tests/fixtures/excerpts_CRLF/posts/post-4.md new file mode 100644 index 0000000..e6aff49 --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/posts/post-4.md @@ -0,0 +1,13 @@ +layout: default.liquid + +title: Custom excerpt separator +published_date: 2016-01-14 21:03:30 -0500 +excerpt_separator: +--- + +# Custom excerpt separator + +Welcome to the 4th post on cobalt.rs! + + +Something below the separator. diff --git a/tests/fixtures/excerpts_CRLF/posts/post-5.md b/tests/fixtures/excerpts_CRLF/posts/post-5.md new file mode 100644 index 0000000..c2498d7 --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/posts/post-5.md @@ -0,0 +1,14 @@ +layout: default.liquid + +title: Both excerpt and excerpt separator are there +published_date: 2016-01-14 21:04:30 -0500 +excerpt: "`excerpt` wins" +excerpt_separator: +--- + +# Both excerpt and excerpt separator are there + +Welcome to the 5th post on cobalt.rs! + + +Something below the separator. diff --git a/tests/fixtures/excerpts_CRLF/posts/post-6.liquid b/tests/fixtures/excerpts_CRLF/posts/post-6.liquid new file mode 100644 index 0000000..6b6c68e --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/posts/post-6.liquid @@ -0,0 +1,13 @@ +layout: default.liquid + +title: Implicit excerpts work only in markdown +published_date: 2016-01-14 21:05:30 -0500 +excerpt_separator: +--- + +

Custom excerpt separator

+ +

Welcome to the 6th post on cobalt.rs!

+ + +

Something below the separator.

diff --git a/tests/fixtures/excerpts_CRLF/posts/post-7.liquid b/tests/fixtures/excerpts_CRLF/posts/post-7.liquid new file mode 100644 index 0000000..43838d1 --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/posts/post-7.liquid @@ -0,0 +1,14 @@ +layout: default.liquid + +title: Explicit excerpts work even in liquid +published_date: 2016-01-14 21:06:30 -0500 +excerpt: explicit excerpt +excerpt_separator: +--- + +

Custom excerpt separator

+ +

Welcome to the 7th post on cobalt.rs!

+ + +

Something below the separator.

diff --git a/tests/fixtures/excerpts_CRLF/posts/post-8.md b/tests/fixtures/excerpts_CRLF/posts/post-8.md new file mode 100644 index 0000000..2287e05 --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/posts/post-8.md @@ -0,0 +1,14 @@ +layout: default.liquid + +title: Reference-style links above first block and separated by blank line resolve +published_date: 2017-02-11 04:45:01 -0000 +--- + +[00]: /0 + [01]: /1 + [02]: /2 + [03]: /3 + +References-style links are placed above the first paragraph, and are separated +from the first paragraph by a single blank line: +[00][] [01][] [02][] [03][] diff --git a/tests/fixtures/excerpts_CRLF/posts/post-9.md b/tests/fixtures/excerpts_CRLF/posts/post-9.md new file mode 100644 index 0000000..da91beb --- /dev/null +++ b/tests/fixtures/excerpts_CRLF/posts/post-9.md @@ -0,0 +1,14 @@ +layout: default.liquid + +title: Reference-style links below first block and separated by blank line resolve +published_date: 2017-02-11 04:48:11 -0000 +--- + +References are placed below the first paragraph, and are separated from the +first paragraph by a single blank line: +[10][] [11][] [12][] [13][] + +[10]: /0 + [11]: /1 + [12]: /2 + [13]: /3 diff --git a/tests/mod.rs b/tests/mod.rs index 32b5eb9..ab14b1a 100644 --- a/tests/mod.rs +++ b/tests/mod.rs @@ -238,6 +238,11 @@ pub fn excerpts() { run_test("excerpts").unwrap(); } +#[test] +pub fn excerpts_crlf() { + run_test("excerpts_CRLF").unwrap(); +} + #[test] pub fn posts_in_subfolder() { run_test("posts_in_subfolder").unwrap(); diff --git a/tests/target/excerpts_CRLF/index.html b/tests/target/excerpts_CRLF/index.html new file mode 100644 index 0000000..a96f419 --- /dev/null +++ b/tests/target/excerpts_CRLF/index.html @@ -0,0 +1,113 @@ + + + + Index + + +
+ +
+

Blog!

+ +
+ +
+

Reference-style links immediately below first block do not resolve

+

Reference-style links immediately below first block do not resolve

+

References are placed immediately below the first paragraph: +30 31 32 33 +30: /0 +31: /1 +32: /2 +33: /3

+ +
+ +
+

Reference-style links immediately above first block

+

Reference-style links immediately above first block

+

References are placed immediately above the first paragraph: +20 21 22 23

+ +
+ +
+

Reference-style links in a non-markdown post do not resolve

+

Reference-style links in a non-markdown post do not resolve

+ References are placed below the first paragraph, and are separated from the +first paragraph by a single blank line: +[40][] [41][] [42][] [43][] +
+ +
+

Reference-style links below first block and separated by blank line resolve

+

Reference-style links below first block and separated by blank line resolve

+

References are placed below the first paragraph, and are separated from the +first paragraph by a single blank line: +10 11 12 13

+ +
+ +
+

Reference-style links above first block and separated by blank line resolve

+

Reference-style links above first block and separated by blank line resolve

+ +
+ +
+

Explicit excerpts work even in liquid

+

Explicit excerpts work even in liquid

+ explicit excerpt +
+ +
+

Implicit excerpts work only in markdown

+

Implicit excerpts work only in markdown

+

Custom excerpt separator

+ +

Welcome to the 6th post on cobalt.rs!

+ +
+ +
+

Both excerpt and excerpt separator are there

+

Both excerpt and excerpt separator are there

+

excerpt wins

+ +
+ +
+

Custom excerpt separator

+

Custom excerpt separator

+

Custom excerpt separator

+

Welcome to the 4th post on cobalt.rs!

+ +
+ +
+

Explicit `excerpt`

+

Explicit `excerpt`

+

Is in markdown

+ +
+ +
+

An empty post means an empty excerpt

+

An empty post means an empty excerpt

+ +
+ +
+

First block is an excerpt

+

First block is an excerpt

+

This is our first Post!

+ +
+ +
+
+ + +
+ + diff --git a/tests/target/excerpts_CRLF/posts/post-1.html b/tests/target/excerpts_CRLF/posts/post-1.html new file mode 100644 index 0000000..8f12487 --- /dev/null +++ b/tests/target/excerpts_CRLF/posts/post-1.html @@ -0,0 +1,21 @@ + + + + First block is an excerpt + + +
+ +
+

First block is an excerpt

+

+

This is our first Post!

+

Welcome to the first post ever on cobalt.rs!

+ +

+
+ + +
+ + diff --git a/tests/target/excerpts_CRLF/posts/post-10.html b/tests/target/excerpts_CRLF/posts/post-10.html new file mode 100644 index 0000000..3f93ee8 --- /dev/null +++ b/tests/target/excerpts_CRLF/posts/post-10.html @@ -0,0 +1,21 @@ + + + + Reference-style links immediately above first block + + +
+ +
+

Reference-style links immediately above first block

+

+

References are placed immediately above the first paragraph: +20 21 22 23

+ +

+
+ + +
+ + diff --git a/tests/target/excerpts_CRLF/posts/post-11.html b/tests/target/excerpts_CRLF/posts/post-11.html new file mode 100644 index 0000000..69e2b72 --- /dev/null +++ b/tests/target/excerpts_CRLF/posts/post-11.html @@ -0,0 +1,28 @@ + + + + Reference-style links immediately below first block do not resolve + + +
+ +
+

Reference-style links immediately below first block do not resolve

+

+

References are placed immediately below the first paragraph: +[30][] [31][] [32][] [33][] +[30]: /0 +[31]: /1 +[32]: /2 +[33]: /3

+

Note that this is at it should be, as the markdown implementations I've tried +(including CommonMark) do not render the above links (when the post is rendered +individually).

+ +

+
+ + +
+ + diff --git a/tests/target/excerpts_CRLF/posts/post-12.html b/tests/target/excerpts_CRLF/posts/post-12.html new file mode 100644 index 0000000..7f84d6a --- /dev/null +++ b/tests/target/excerpts_CRLF/posts/post-12.html @@ -0,0 +1,27 @@ + + + + Reference-style links in a non-markdown post do not resolve + + +
+ +
+

Reference-style links in a non-markdown post do not resolve

+

+ References are placed below the first paragraph, and are separated from the +first paragraph by a single blank line: +[40][] [41][] [42][] [43][] + +[40]: /0 + [41]: /1 + [42]: /2 + [43]: /3 + +

+
+ + +
+ + diff --git a/tests/target/excerpts_CRLF/posts/post-2.html b/tests/target/excerpts_CRLF/posts/post-2.html new file mode 100644 index 0000000..5dfd6ee --- /dev/null +++ b/tests/target/excerpts_CRLF/posts/post-2.html @@ -0,0 +1,19 @@ + + + + An empty post means an empty excerpt + + +
+ +
+

An empty post means an empty excerpt

+

+ +

+
+ + +
+ + diff --git a/tests/target/excerpts_CRLF/posts/post-3.html b/tests/target/excerpts_CRLF/posts/post-3.html new file mode 100644 index 0000000..12b6c04 --- /dev/null +++ b/tests/target/excerpts_CRLF/posts/post-3.html @@ -0,0 +1,21 @@ + + + + Explicit `excerpt` + + +
+ +
+

Explicit `excerpt`

+

+

This is our third Post!

+

Welcome to the third post ever on cobalt.rs!

+ +

+
+ + +
+ + diff --git a/tests/target/excerpts_CRLF/posts/post-4.html b/tests/target/excerpts_CRLF/posts/post-4.html new file mode 100644 index 0000000..a1f06ff --- /dev/null +++ b/tests/target/excerpts_CRLF/posts/post-4.html @@ -0,0 +1,23 @@ + + + + Custom excerpt separator + + +
+ +
+

Custom excerpt separator

+

+

Custom excerpt separator

+

Welcome to the 4th post on cobalt.rs!

+ +

Something below the separator.

+ +

+
+ + +
+ + diff --git a/tests/target/excerpts_CRLF/posts/post-5.html b/tests/target/excerpts_CRLF/posts/post-5.html new file mode 100644 index 0000000..26f1398 --- /dev/null +++ b/tests/target/excerpts_CRLF/posts/post-5.html @@ -0,0 +1,23 @@ + + + + Both excerpt and excerpt separator are there + + +
+ +
+

Both excerpt and excerpt separator are there

+

+

Both excerpt and excerpt separator are there

+

Welcome to the 5th post on cobalt.rs!

+ +

Something below the separator.

+ +

+
+ + +
+ + diff --git a/tests/target/excerpts_CRLF/posts/post-6.html b/tests/target/excerpts_CRLF/posts/post-6.html new file mode 100644 index 0000000..8d906fe --- /dev/null +++ b/tests/target/excerpts_CRLF/posts/post-6.html @@ -0,0 +1,25 @@ + + + + Implicit excerpts work only in markdown + + +
+ +
+

Implicit excerpts work only in markdown

+

+

Custom excerpt separator

+ +

Welcome to the 6th post on cobalt.rs!

+ + +

Something below the separator.

+ +

+
+ + +
+ + diff --git a/tests/target/excerpts_CRLF/posts/post-7.html b/tests/target/excerpts_CRLF/posts/post-7.html new file mode 100644 index 0000000..e426b19 --- /dev/null +++ b/tests/target/excerpts_CRLF/posts/post-7.html @@ -0,0 +1,25 @@ + + + + Explicit excerpts work even in liquid + + +
+ +
+

Explicit excerpts work even in liquid

+

+

Custom excerpt separator

+ +

Welcome to the 7th post on cobalt.rs!

+ + +

Something below the separator.

+ +

+
+ + +
+ + diff --git a/tests/target/excerpts_CRLF/posts/post-8.html b/tests/target/excerpts_CRLF/posts/post-8.html new file mode 100644 index 0000000..ffedef0 --- /dev/null +++ b/tests/target/excerpts_CRLF/posts/post-8.html @@ -0,0 +1,22 @@ + + + + Reference-style links above first block and separated by blank line resolve + + +
+ +
+

Reference-style links above first block and separated by blank line resolve

+

+

References-style links are placed above the first paragraph, and are separated +from the first paragraph by a single blank line: +00 01 02 03

+ +

+
+ + +
+ + diff --git a/tests/target/excerpts_CRLF/posts/post-9.html b/tests/target/excerpts_CRLF/posts/post-9.html new file mode 100644 index 0000000..4b1fd2f --- /dev/null +++ b/tests/target/excerpts_CRLF/posts/post-9.html @@ -0,0 +1,22 @@ + + + + Reference-style links below first block and separated by blank line resolve + + +
+ +
+

Reference-style links below first block and separated by blank line resolve

+

+

References are placed below the first paragraph, and are separated from the +first paragraph by a single blank line: +10 11 12 13

+ +

+
+ + +
+ +