Displaying "\n" in phoenix templates

I have a string which has “\n” but they are not being displayed properly. “\n” is being treated as if it does not exist.

<p>Question : <%= Phoenix.HTML.raw(rr["question"]) %></p>
<p>Question : <%= rr["question"] %></p>

both of above return same result with “\n” being eaten up by phoenix template.

What am i missing?

Whitespace is not significant in plain html. Either use Phoenix.HTML.Format.text_to_html to convert whitespace into the related html tags or wrap the whole html in <pre></pre> tags.

4 Likes