Spaces between tags in HAML

Is there a way to specify "pretty-printed" formatting around HTML tags? I want to be able to put spaces between HTML blocks, so this is:

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

... translates to this:

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


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


<!-- analytics -->
...

I know you can make comments using /, is there something similar for spaces between tags? Maybe something like this

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

Where \or :scan there be custom filters?

Or even something like = space(10)10 line breaks? Or maybe even ~on its own, but that doesn't work.

+3
source share
4 answers
#container
- haml_concat("\n" * 5)
#footer

haml_concat - .

+5

Ruby :

.main
  .container
    %p Something

  ~ "\n" * 5

  .footer
    %p Footer

~ - .

+1
\#container  
= ('< br />'*5).html_safe 

\#footer
0
source

I wrote a special filter for this kind of thing: https://gist.github.com/dmitry/6050231

To use this, you just need to add :s, as in your example:

#footer
:s
:s
/ analytics
0
source

Source: https://habr.com/ru/post/1735364/


All Articles