br标签未在Haml on Rails 3中关闭 [英] br tag not closing in Haml on Rails 3

查看:79
本文介绍了br标签未在Haml on Rails 3中关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让Haml关闭b​​r标签时遇到问题.我没有运气就尝试了以下方法:

I am having a problem getting Haml to close br tags. I have tried the following with no luck:

%br  
%br/

我希望这会导致产生<br />,但即使结尾处带有斜杠字符,它也始终输出为<br>.我也尝试过将以下选项添加到application.rb中(我尝试过environment.rb)

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']

我错过了什么吗?我虽然Haml应该默认情况下会自动关闭这些标签?

Am I missing something? I though Haml was supposed to autoclose these tags by default??

推荐答案

好,我发现了问题所在.在使用Rails 3时,Haml默认情况下会输出HTML5.我没有意识到<br>在HTML5中是有效的语法.我试图让它通过W3C语义提取器,所以我需要<br />.为了使它起作用,您将需要更新自动关闭的Haml选项并将其设置为xhtml.将此代码放入类内的application.rb中.

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

更多信息在这里:

http://github.com/nex3/haml/issuesearch?state = closed& q = close#issue/155

这篇关于br标签未在Haml on Rails 3中关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆