I am having a problem getting Haml to close br tags. I have tried the following with no luck:
%br
%br/
I expect this to result in <br />
, but it always outputs as <br>
, even with the slash character on the end. I have also tried adding the following options to application.rb (and I tried environment.rb)
Haml::Template.options[:autoclose] = ['meta', 'img', 'link', 'br', 'hr', 'input', 'area', 'param', 'col', 'base']
Am I missing something? I though Haml was supposed to autoclose these tags by default??
Ok, I found out the problem. Haml outputs HTML5 by default when using Rails 3. I didn't realize that <br>
was valid syntax in HTML5. I was trying to get this to pass the W3C semantic extractor, so I need <br />
instead. In order to get this to work, you will need to update the Haml options for autoclose and set it to xhtml. Drop this code into your application.rb inside the class.
Haml::Template.options[:format] = :xhtml
More info here:
http://github.com/nex3/haml/issuesearch?state=closed&q=close#issue/155
But, if I want xhtml5 (i.e. html5 with autoclose) there's no way to do it! I, like many other users, have tried overriding the :autoclose list and it just doesn't work.
According to the haml docs:
Haml::Template.options[:format] = :xhtml
should be placed in config/environment.rb.
Placing it in environment.rb works for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With