HAML - a very strange difference in the retreat - a mistake?

This haml

%script{:type => "text/javascript"} :plain $(document).ready(function() { bar(); var foo = foo_func("#{}"); }); 

as expected, gives the following:

 <script type='text/javascript'> $(document).ready(function() { bar(); var foo = foo_func(""); }); </script> 

But this ALMOST IDENTICAL HAML (changed only bar() to prep() ):

 %script{:type => "text/javascript"} :plain $(document).ready(function() { prep(); var foo = foo_func("#{}"); }); 

gives the following:

 <script type='text/javascript'> $(document).ready(function() { prep(); var foo = foo_func(""); }); </script> 

A NOTE OF THE AUXILIARY INdentation in the second case.

Why does changing bar() to prep() cause this weird difference?

+4
source share
1 answer

This is caused by the pre characters in prep() matching the regular expression that Haml uses to handle spaces.

In Haml, you use spaces to indicate the contents of elements, and this is usually normal because when viewing HTML spaces, it is "crushed" so that it appears as a single character. However, spaces are important in some HTML elements ( pre , code and textarea ), and Haml is trying to detect and process these elements. In this case, the regular expression is matched, and the block after the first line is not indented.

This code has been changed in the latest version (currently 4.0.1.rc.1), and this does not happen in this version. Ive also created a query that corrects a regular expression in branch 3-1 .

+3
source

All Articles