HAML -添加type=text/css到标签:css filter

时间:2022-06-04 20:31:15

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 :css filter seems like it should be more "elegant"?!? Or, did I miss something (I rarely deal with inline CSS) and type is no longer necessary?!?

我可以使用蛮力%style(类型=“text/css”),但是HAML的:css过滤器看起来应该更“优雅”?或者,我是否遗漏了一些东西(我很少处理内联CSS),而类型不再是必需的?

2 个解决方案

#1


20  

Haml will output the type attribute if the format option is set to xhtml or html4. If the format is set to html5 the attribute will be omitted.

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

See the Haml docs on options and the source of the CSS filter.

请参阅Haml文档中的选项和CSS过滤器的源代码。

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

Haml 3.1中的默认值。x是xhtml,但是在Rails中是html5,因为这是Rails的默认值。在Haml 4+中,默认将是html5。(同样在4+中,当格式为html4或html5时,CDATA标记将被默认省略。)

#2


9  

type defaults to text/css as of HTML5, and has always done so in practice (i.e. in browser implementations).

在HTML5中输入默认的文本/css,并在实践中一直这样做(例如在浏览器实现中)。

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

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

#1


20  

Haml will output the type attribute if the format option is set to xhtml or html4. If the format is set to html5 the attribute will be omitted.

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

See the Haml docs on options and the source of the CSS filter.

请参阅Haml文档中的选项和CSS过滤器的源代码。

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

Haml 3.1中的默认值。x是xhtml,但是在Rails中是html5,因为这是Rails的默认值。在Haml 4+中,默认将是html5。(同样在4+中,当格式为html4或html5时,CDATA标记将被默认省略。)

#2


9  

type defaults to text/css as of HTML5, and has always done so in practice (i.e. in browser implementations).

在HTML5中输入默认的文本/css,并在实践中一直这样做(例如在浏览器实现中)。

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

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