Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

%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:

<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?!?

like image 418
Meltemi Avatar asked Jan 16 '12 18:01

Meltemi


2 Answers

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.

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

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.)

like image 123
matt Avatar answered Nov 13 '22 04:11

matt


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

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

like image 10
Domenic Avatar answered Nov 13 '22 04:11

Domenic