1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

Compile html comment

This commit is contained in:
Takashi Kokubun 2015-10-12 00:37:01 +09:00
parent 5f3064e5f0
commit 4fff10c075
3 changed files with 25 additions and 16 deletions

View file

@ -20,6 +20,8 @@ module Hamlit
case node.type
when :root
compile_children(node)
when :comment
compile_comment(node)
when :doctype
compile_doctype(node)
when :tag
@ -39,6 +41,13 @@ module Hamlit
@doctype_compiler.compile(node)
end
def compile_comment(node)
if node.children.empty?
return [:html, :comment, [:static, " #{node.value[:text]} "]]
end
[:html, :comment, compile_children(node)]
end
def compile_tag(node)
@tag_compiler.compile(node) { |n| compile_children(n) }
end

View file

@ -28,7 +28,7 @@ module Hamlit
end
def prepend_whitespace?(node)
return false if node.type != :tag
return false unless %i[comment tag].include?(node.type)
!nuke_inner_whitespace?(node)
end
@ -54,7 +54,7 @@ module Hamlit
case node.type
when :doctype
node.value[:type] != 'xml'
when :plain, :tag
when :plain, :tag, :comment
true
else
false

View file

@ -335,20 +335,20 @@ silent comments:
%div
foo
html: ''
# markup comments:
# an inline markup comment:
# haml: "/ comment"
# html: "<!-- comment -->"
# a nested markup comment:
# haml: |-
# /
# comment
# comment2
# html: |-
# <!--
# comment
# comment2
# -->
markup comments:
an inline markup comment:
haml: "/ comment"
html: "<!-- comment -->"
a nested markup comment:
haml: |-
/
comment
comment2
html: |-
<!--
comment
comment2
-->
# conditional comments:
# a conditional comment:
# haml: |-