views:

267

answers:

2

Is there a way to specify "pretty-print"-like formatting around HTML tags? I want to be able to put whitespace between blocks of HTML, so this:

<!-- container -->
<div id='container'>
</div>
<!-- footer -->
<div id="footer">
</div>
<!-- analytics -->
...

...is converted to this:

<!-- container -->
<div id='container'>
</div>


<!-- footer -->
<div id="footer">
</div>


<!-- analytics -->
...

I know you can do comments with /, is there something like that for whitespace between tags? Maybe something like this

/ container
#container
\
\
/ footer
#footer
:s
:s
/ analytics

Where the \ or :s could be custom filters?

Or even something like = space(10) for 10 line breaks? Or maybe even ~ by itself but that doesn't work.

+1  A: 

You can evaluate Ruby block to insert additional newlines:

.main
  .container
    %p Something

  ~ "\n" * 5

  .footer
    %p Footer

This also uses ~ - whitespace preservation.

Dmytrii Nagirniak
I was trying that but it doesn't actually output the html with 5 lines between tags, just 1 :/. currently you'd have to have 5 ~, one on each line, which obscures everything too much.
viatropos
+4  A: 
#container
- haml_concat("\n" * 5)
#footer

The haml_concat helper directly concatenates text onto the output buffer, without any sort of pre-processing.

nex3
there it is! thanks :)
viatropos