2012-01-16 22 views
22

我試圖在HAML文件中添加一些內聯CSS。我認爲HAML - add type = text/css to <style> tag with:css filter

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

會產生:

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

但事實並非如此。因爲它省去了type="text/css"和生產:

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

我可以只用蠻力%style(type="text/css")但HAML的:css過濾器好像它應該更加「優雅」?!?或者,我錯過了什麼(我很少處理內聯CSS),並且不再需要type?!?

回答

19

如果format選項設置爲xhtmlhtml4,Haml將輸出type屬性。如果格式設置爲html5,則該屬性將被省略。

請參閱Haml docs on optionssource of the CSS filter

Haml 3.1.x中的默認值是xhtml,除了Rails是html5之外,因爲這是Rails的默認值。在Haml 4+中,整個過程默認爲html5。 (如果格式爲html4html5,則默認情況下,4個CDATA標籤將被忽略。)

+7

當然是綠色複選標記的竊取,先生。 +1 – Domenic 2012-01-17 17:24:16