33

我有问题<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>
4

2 回答 2

64

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

于 2010-01-03T05:03:58.230 回答
2

当从 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)
于 2015-07-30T14:37:36.623 回答