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:
parent
5f3064e5f0
commit
4fff10c075
3 changed files with 25 additions and 16 deletions
|
@ -20,6 +20,8 @@ module Hamlit
|
||||||
case node.type
|
case node.type
|
||||||
when :root
|
when :root
|
||||||
compile_children(node)
|
compile_children(node)
|
||||||
|
when :comment
|
||||||
|
compile_comment(node)
|
||||||
when :doctype
|
when :doctype
|
||||||
compile_doctype(node)
|
compile_doctype(node)
|
||||||
when :tag
|
when :tag
|
||||||
|
@ -39,6 +41,13 @@ module Hamlit
|
||||||
@doctype_compiler.compile(node)
|
@doctype_compiler.compile(node)
|
||||||
end
|
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)
|
def compile_tag(node)
|
||||||
@tag_compiler.compile(node) { |n| compile_children(n) }
|
@tag_compiler.compile(node) { |n| compile_children(n) }
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,7 +28,7 @@ module Hamlit
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepend_whitespace?(node)
|
def prepend_whitespace?(node)
|
||||||
return false if node.type != :tag
|
return false unless %i[comment tag].include?(node.type)
|
||||||
!nuke_inner_whitespace?(node)
|
!nuke_inner_whitespace?(node)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ module Hamlit
|
||||||
case node.type
|
case node.type
|
||||||
when :doctype
|
when :doctype
|
||||||
node.value[:type] != 'xml'
|
node.value[:type] != 'xml'
|
||||||
when :plain, :tag
|
when :plain, :tag, :comment
|
||||||
true
|
true
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
|
|
|
@ -335,20 +335,20 @@ silent comments:
|
||||||
%div
|
%div
|
||||||
foo
|
foo
|
||||||
html: ''
|
html: ''
|
||||||
# markup comments:
|
markup comments:
|
||||||
# an inline markup comment:
|
an inline markup comment:
|
||||||
# haml: "/ comment"
|
haml: "/ comment"
|
||||||
# html: "<!-- comment -->"
|
html: "<!-- comment -->"
|
||||||
# a nested markup comment:
|
a nested markup comment:
|
||||||
# haml: |-
|
haml: |-
|
||||||
# /
|
/
|
||||||
# comment
|
comment
|
||||||
# comment2
|
comment2
|
||||||
# html: |-
|
html: |-
|
||||||
# <!--
|
<!--
|
||||||
# comment
|
comment
|
||||||
# comment2
|
comment2
|
||||||
# -->
|
-->
|
||||||
# conditional comments:
|
# conditional comments:
|
||||||
# a conditional comment:
|
# a conditional comment:
|
||||||
# haml: |-
|
# haml: |-
|
||||||
|
|
Loading…
Add table
Reference in a new issue