代码之家  ›  专栏  ›  技术社区  ›  Cheng

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

  •  33
  • Cheng  · 技术社区  · 16 年前

    我对这件事有意见 <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>
    
    2 回复  |  直到 9 年前
        1
  •  64
  •   Peter Coulton    14 年前

    你需要使用 #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>
    

    :preserve:escaped .

        2
  •  2
  •   Allen    11 年前

    当从div或其他标记内的变量中表示类似于“pre”的文本时,请使用

    .text.plain= preserve(@mail.body.to_s)
    

    以及CSS“空白:预包装;”。使用单行版本,因为两行仍然会缩进第一行。

    / BAD: Will leave the first line incorrectly indented!
    .text.plain
      = preserve(@mail.body.to_s)