diff --git a/lib/hamlit/whitespace_handler.rb b/lib/hamlit/whitespace_handler.rb index db0e25d0..1564c4aa 100644 --- a/lib/hamlit/whitespace_handler.rb +++ b/lib/hamlit/whitespace_handler.rb @@ -2,6 +2,9 @@ module Hamlit class WhitespaceHandler def compile_children(node, &block) temple = [:multi] + return temple if node.children.empty? + + temple << [:static, "\n"] if prepend_whitespace?(node) node.children.each do |n| temple << yield(n) temple << [:static, "\n"] if insert_whitespace?(n) @@ -11,6 +14,15 @@ module Hamlit private + def prepend_whitespace?(node) + case node.type + when :tag + true + else + false + end + end + def insert_whitespace?(node) case node.type when :doctype diff --git a/test/haml-spec/tests.yml b/test/haml-spec/tests.yml index dbe8fee4..fada4879 100644 --- a/test/haml-spec/tests.yml +++ b/test/haml-spec/tests.yml @@ -173,37 +173,37 @@ tags with unusual CSS identifiers: #
text
# # -# tags with nested content: -# Nested content simple tag: -# haml: |- -# %p -# hello -# html: |- -#-# hello -#
-# Nested content tag with CSS: -# haml: |- -# %p.class1 -# hello -# html: |- -#-# hello -#
-# Nested content multiple simple tags: -# haml: |- -# %div -# %div -# %p -# text -# html: |- -#-# text -#
-#+ hello +
+ Nested content tag with CSS: + haml: |- + %p.class1 + hello + html: |- ++ hello +
+ Nested content multiple simple tags: + haml: |- + %div + %div + %p + text + html: |- ++ text +
+Bar\nBaz"