Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Haml to render the contents of a pre tag correctly?

I read the Haml docs where they talk about the pre tag and "preserving whitespace". According to the docs, pre "preserves whitespace" by default and you need to use the ~ operator to output the contents of the tag to get it to render correctly. Following the recommended practice, I have this:

%pre
  ~ @calendar.main_template

The output in the browser:

(This may be a little confusing -- the app is letting the user manipulate Haml code, so I'm actually displaying Haml code here in the UI.)

%div
                = events

What output want:

%div
  = events

I also tried using = instead of ~. Also tried %pre>, %pre<, and %pre>< all with identical results.

like image 808
Ethan Avatar asked Feb 24 '09 20:02

Ethan


1 Answers

You want preserve.

%pre
  = preserve "I like\n  Cheese"
like image 166
Alex Wayne Avatar answered Oct 19 '22 03:10

Alex Wayne