How to remove unwanted indent from HAML's pre tag

Viewed 7426

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>
2 Answers

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.

Related