Reputation: 2459
I have this variable in slim:
- foo = 'my \n desired multiline <br/> string'
#{foo}
When I parse the output using the slimrb command line command the contents of the variable are encoded:
my \n desired multiline <br/> string
How can I have slimrb
output the raw contents in order to generate multi-line strings?
Note that neither .html_safe
nor .raw
are available.
Upvotes: 2
Views: 3446
Reputation: 2357
An easier way is to use Line Indicators as verbatim texts |
. Documentation here . For example;
p
| This line is on the left margin.
This line will have one space in front of it.
Upvotes: 2
Reputation: 79783
There are two issues here. First in Ruby strings using single quotes – '
– don’t convert \n
to newlines, they remain as literal \
and n
. You need to use double quotes. This applies to Slim too.
Second, Slim HTML escapes the result of interpolation by default. To avoid this use double braces around the code. Slim also HTML escapes Ruby output by default (using =
). To avoid escaping in that case use double equals (==
).
Combining these two, your code will look something like:
- foo = "my \n desired multiline <br/> string"
td #{{foo}}
This produces:
<td>my
desired multiline <br/> string</td>
Upvotes: 4