如何从HAML的预标记中删除不需要的缩进

Che*_*eng 33 haml

我有问题<pre>,这是我的代码,截图附在下面.如何删除缩进?

%pre.code
    :escaped
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
            "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html>
            <head></head>
            <body>
                <form>
                    <input type="text" name="empID" />
                    <input type="submit"/>      
                </form> 
            </body>
        </html>
Run Code Online (Sandbox Code Playgroud)

Nat*_*aum 63

您需要使用#preserve帮助程序将换行符转换pre为换行符实体,如下所示:

%pre.code
    = preserve do
        :escaped
            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
            <html>
                <head></head>
                <body>
                    <form>
                        <input type="text" name="empID" />
                        <input type="submit"/>        
                    </form>   
                </body>
            </html>
Run Code Online (Sandbox Code Playgroud)

将来,您将能够嵌套过滤器,因此您可以这样做:preserve:escaped.

  • `:preserve`不会逃避你的内容,而`:escaped`将不会保留它.这就是你需要嵌套过滤器的原因. (2认同)
  • 我遇到了同样的问题,但我不得不使用"= preserve do",而不是" - preserve do",可能是版本问题. (2认同)