简体   繁体   English

HTML到Haml的转换javascript

[英]Html to Haml conversion javascript

I have this html code. 我有这个html代码。 I want it to convert to haml format. 我希望将其转换为haml格式。 --> ->

    <script type="text/javascript">
        window.jQuery || document.write("<script src='assets/jquery-2.0.3.min.js'>"+"<"+"/script>");
    </script>

    <!--<![endif]-->

This is how I convert it to haml. 这就是我将其转换为haml的方式。

/ [if !IE]>
  :javascript
    window.jQuery || document.write("<script src='assets/jquery-2.0.3.min.js'>"+"<"+"/script>");
/ <![endif]

but I got this error Illegal nesting: nesting within a tag that already has content is illegal. 但我收到此错误非法嵌套:在已经具有内容的标记中嵌套是非法的。 Any idea why? 知道为什么吗? or what is the right way to convert this code to haml? 还是将这段代码转换为haml的正确方法是什么?

Haml includes support for IE conditional comments , the sytax is / [cond] , without the closing > Haml包括对IE条件注释的支持,其语法为/ [cond] ,而无需关闭>

In your first line: 在第一行:

/ [if !IE]>

the last > is being treated as content, and you also nest the :javascript filter as content. 最后一个>被视为内容,您也将:javascript过滤器嵌套为内容。 This is why you get the nesting within a tag that already has content is illegal error. 这就是为什么您nesting within a tag that already has content is illegal错误的原因。

However, you can't use the !IE condition this way , you'll end up with a single comment that all browsers will ignore. 但是,您不能以这种方式使用!IE条件 ,最终将得到一个注释,所有浏览器都将忽略该注释。 You'll need to no something like this, using literal HTML: 使用文字HTML,您不需要这样的事情:

<!--[if !IE]> -->
:javascript
  window.jQuery || document.write("<script src='assets/jquery-2.0.3.min.js'>"+"<"+"/script>");
<!-- <![endif]-->

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM