mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Insert newline inside tag
This commit is contained in:
parent
db016c48c6
commit
15ae22e3b2
2 changed files with 49 additions and 37 deletions
|
@ -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
|
||||
|
|
|
@ -173,37 +173,37 @@ tags with unusual CSS identifiers:
|
|||
# <p>text</p>
|
||||
# </div>
|
||||
# </div>
|
||||
# tags with nested content:
|
||||
# Nested content simple tag:
|
||||
# haml: |-
|
||||
# %p
|
||||
# hello
|
||||
# html: |-
|
||||
# <p>
|
||||
# hello
|
||||
# </p>
|
||||
# Nested content tag with CSS:
|
||||
# haml: |-
|
||||
# %p.class1
|
||||
# hello
|
||||
# html: |-
|
||||
# <p class='class1'>
|
||||
# hello
|
||||
# </p>
|
||||
# Nested content multiple simple tags:
|
||||
# haml: |-
|
||||
# %div
|
||||
# %div
|
||||
# %p
|
||||
# text
|
||||
# html: |-
|
||||
# <div>
|
||||
# <div>
|
||||
# <p>
|
||||
# text
|
||||
# </p>
|
||||
# </div>
|
||||
# </div>
|
||||
tags with nested content:
|
||||
Nested content simple tag:
|
||||
haml: |-
|
||||
%p
|
||||
hello
|
||||
html: |-
|
||||
<p>
|
||||
hello
|
||||
</p>
|
||||
Nested content tag with CSS:
|
||||
haml: |-
|
||||
%p.class1
|
||||
hello
|
||||
html: |-
|
||||
<p class='class1'>
|
||||
hello
|
||||
</p>
|
||||
Nested content multiple simple tags:
|
||||
haml: |-
|
||||
%div
|
||||
%div
|
||||
%p
|
||||
text
|
||||
html: |-
|
||||
<div>
|
||||
<div>
|
||||
<p>
|
||||
text
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
tags with HTML-style attributes:
|
||||
HTML-style one attribute:
|
||||
haml: "%p(a='b')"
|
||||
|
@ -477,17 +477,17 @@ Ruby-style interpolation:
|
|||
# html: <"&>
|
||||
# config:
|
||||
# escape_html: 'true'
|
||||
# boolean attributes:
|
||||
boolean attributes:
|
||||
# boolean attribute with XHTML:
|
||||
# haml: "%input(checked=true)"
|
||||
# html: "<input checked='checked' />"
|
||||
# config:
|
||||
# format: xhtml
|
||||
# boolean attribute with HTML:
|
||||
# haml: "%input(checked=true)"
|
||||
# html: "<input checked>"
|
||||
# config:
|
||||
# format: html5
|
||||
boolean attribute with HTML:
|
||||
haml: "%input(checked=true)"
|
||||
html: "<input checked>"
|
||||
config:
|
||||
format: html5
|
||||
# whitespace preservation:
|
||||
# following the '~' operator:
|
||||
# haml: ~ "Foo\n<pre>Bar\nBaz</pre>"
|
||||
|
|
Loading…
Add table
Reference in a new issue