Skip to content

Commit

Permalink
Skip any blank lines at the beginning of template
Browse files Browse the repository at this point in the history
  • Loading branch information
Rakoth authored and doomspork committed Oct 29, 2017
1 parent 894afec commit 245aa21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/slime/parser/transform.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ defmodule Slime.Parser.Transform do
@spec transform(atom, iolist, index) :: ast
def transform(:document, input, _index) do
case input do
[[], tags | _] -> tags
[doctype, [""] | _] -> [doctype]
[doctype, tags | _] -> [doctype | tags]
[_blank_lines, [], tags | _] -> tags
[_blank_lines, doctype, [""] | _] -> [doctype]
[_blank_lines, doctype, tags | _] -> [doctype | tags]
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/slime_parser.peg.eex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
document <- doctype? tags? eof;
document <- (space? crlf)* doctype? tags? eof;

doctype <- space? 'doctype' space name:(!eol .)+ eol;

Expand Down
9 changes: 9 additions & 0 deletions test/renderer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,13 @@ defmodule RendererTest do
assert render(example_unix) == expected_rendered_output
assert render(example_windows) == expected_rendered_output
end

test "template can start with an empty line" do
slime = """
div test
"""

assert render(slime) == "<div>test</div>"
end
end

0 comments on commit 245aa21

Please sign in to comment.