How to remove unwanted indent from HAML's pre tag

元气小坏坏 提交于 2019-11-29 00:25:13

问题


I have problem with <pre>, here is my code, and the screenshot is attached below. How to remove the indents?

%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>

回答1:


You need to use the #preserve helper to convert the newlines in the pre to newline entities, like so:

%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>

In the future, you'll be able to nest filters, so you can do :preserve:escaped.




回答2:


When representing "pre" like text from a variable inside a div or other tag, use

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

along with CSS "white-space: pre-wrap;". Use the one-line version, because the two-line will still indent the first line.

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


来源:https://stackoverflow.com/questions/1993993/how-to-remove-unwanted-indent-from-hamls-pre-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!