Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping HTML in HAML

Tags:

escaping

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.

like image 535
punund Avatar asked Dec 12 '22 07:12

punund


2 Answers

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.
like image 119
Evgenii Avatar answered Feb 19 '23 08:02

Evgenii


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
like image 23
Joe Van Dyk Avatar answered Feb 19 '23 08:02

Joe Van Dyk