punund
punund

Reputation: 4421

Escaping HTML in HAML

Another stupid HAML question. I need to escape HTML in plain strings, without "=":

%p
  This paragraph has <n> lines.

Whatever I do (like prepending "&"), it still renders as

This paragraph has  lines.

I am using Rails 3.1.

Upvotes: 5

Views: 9591

Answers (3)

Evgenii
Evgenii

Reputation: 37349

Yes, you can escape HTML with :escaped filter.

Works the same as plain, but HTML-escapes the text before placing it in the document.

Example:

%p
  :escaped
    This paragraph has <n> lines.

Upvotes: 11

Joe Van Dyk
Joe Van Dyk

Reputation: 6950

Check the HAML documentation here: http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#escaping_html

There might be a better way of doing it, but this does work:

& This paragraph has #{"<n>"} lines

That will generate

This paragraph has &lt;n&gt; lines

Upvotes: 2

smendola
smendola

Reputation: 2311

This paragraph has &lt;n&gt; lines

Upvotes: 0

Related Questions