HAML - 使用 :css 过滤器将 type=text/css 添加到 <style> 标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8884316/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 02:40:45  来源:igfitidea点击:

HAML - add type=text/css to <style> tag with :css filter

csshamlsassnoscript

提问by Meltemi

I'm trying to add some inline CSS in a HAML file. I thought that

我正在尝试在 HAML 文件中添加一些内联 CSS。我认为

%noscript
  :css
    .pagecontent {display:none;}

would produce:

会产生:

<noscript>
  <style type="text/css">
    /*<![CDATA[*/
      .pagecontent {display:none;}
    /*]]>*/
  </style>
</noscript>

but it doesn't. As it leaves out the type="text/css"and produces:

但事实并非如此。因为它省略了type="text/css"和 产生:

<noscript>
  <style>
    /*<![CDATA[*/
      .pagecontent {display:none;}
    /*]]>*/
  </style>
</noscript>

I could just use brute force %style(type="text/css")but HAML's :cssfilter seems like it shouldbe more "elegant"?!? Or, did I miss something (I rarely deal with inline CSS) and typeis no longer necessary?!?

我可以只使用蛮力,%style(type="text/css")但 HAML 的:css过滤器似乎应该更“优雅”?!?或者,我是否错过了一些东西(我很少处理内联 CSS)并且type不再需要?!?

采纳答案by matt

Haml will output the typeattribute if the formatoption is set to xhtmlor html4. If the format is set to html5the attribute will be omitted.

type如果format选项设置为xhtml或 ,Haml 将输出属性html4。如果格式设置html5为该属性将被省略。

See the Haml docs on optionsand the source of the CSS filter.

请参阅有关选项CSS 过滤器来源Haml 文档

The default in Haml 3.1.x is xhtml, except in Rails when it is html5since that is the Rails default. In Haml 4+ the default will be html5throughout. (Also in 4+ the CDATA tags will be left out by default when the format is html4or html5.)

Haml 3.1.x 中的默认值是xhtml,但在 Rails 中除外,html5因为这是 Rails 的默认值。在 Haml 4+ 中,默认值将html5贯穿始终。(同样在 4+ 中,当格式为html4或时,默认情况下 CDATA 标签将被省略html5。)

回答by Domenic

typedefaults to text/cssas of HTML5, and has always done so in practice (i.e. in browser implementations).

type默认text/css为 HTML5,并且在实践中一直这样做(即在浏览器实现中)。

So yes, type="text/css"is not necessary (and never has been).

所以是的,type="text/css"没有必要(而且从来没有)。