Reputation: 40473
Here is my Haml:
%a{:href => "/settings", "data-icon" => "⚙"}
Which outputs:
<a data-icon='&#9881;' href='/settings'>Settings</a>
I want to output:
<a data-icon='⚙' href='/settings'>Settings</a>
So I've tried escaping the ampersand:
%a{:href => "/settings", "data-icon" => "\⚙"}
But it seems escapes only work for the first character of a line.
I've also tried different methods of interpolation/escaping with no success:
"#{"⚙"}"
Using plain html (<a href="/settings" data-icon="⚙">Settings</a>
) is a stopgap measure that I do not consider a solution. What if I want to set the data-icon
programatically?
Another option is:
%a{:href => "#", "data-icon" => "⚙"} Settings
But what if I want to use PUA characters? It also makes it a lot harder to tell what the character is in the markup.
Upvotes: 1
Views: 949
Reputation: 79733
You need to set the escape_attrs
option to false
or :once
.
$ haml --no-escape-attrs
%a{:href => "/settings", "data-icon" => "⚙"}
output:
<a data-icon='⚙' href='/settings'></a>
--no-escape-attrs
sets the escape_attrs
option to false
from the command line. See the docs for info on how to set options in other cases.
(It doesn’t look like codepen.io lets you specify Haml options, so I can’t provide a demo there).
Upvotes: 1