plain-text
Plain text and interpolation
Any line whose first non-space character is not a HAML sigil is plain text. Plain text is emitted as-is at the current indent level.
%div
Hello world
Another linerenders to:
<div>
Hello world
Another line
</div>Backslash escape
To produce text that begins with a HAML sigil, prefix the line with \. The
backslash is stripped from the output.
\%foo
\.bar
\#hashrenders to:
%foo
.bar
#hashInterpolation
#{ ... } evaluates a Raku expression, HTML-escapes the result, and emits it.
%p Hello, #{ $name }!with :locals(%(name => 'world')) renders to:
<p>Hello, world!</p>!{ ... } evaluates and emits the result without HTML-escaping. Use it when
the value is already known-safe HTML.
%p !{ $raw }with :locals(%(raw => '<b>bold</b>')) renders to:
<p><b>bold</b></p>To produce a literal #{...} or !{...}, escape the leading sigil with a
backslash:
%p \#{ literal }renders to:
<p>#{ literal }</p>Interpolation is recognized in tag content, plain text lines, and inside double-quoted attribute strings:
%a{ href: "/users/#{ $id }" } Profilewith :locals(%(id => 7)) renders to:
<a href='/users/7'>Profile</a>Single-quoted attribute strings are literal ā no interpolation is performed:
%a{ title: 'Hello #{name}' } gorenders to:
<a title='Hello #{name}'>go</a>Escaping rules
Inside #{ ... }, the value is HTML-escaped before emission, so user input
cannot inject markup:
%p #{ $tag }with :locals(%(tag => '<b>')) renders to:
<p><b></p>Inside !{ ... }, the value is emitted raw. Inside attribute values, the
final attribute value is escaped once after interpolation, so #{} and
!{} produce equivalent output for attributes.
Multi-line content
The legacy | line-continuation operator from Ruby HAML 3 is not
supported. Wrap multi-line content in a tag or use embedded Raku for
formatting:
%p
First line
Second line