SimpleFormat
Rail’s simple_format helper for Phoenix.HTML
For more documentation, please see SimpleFormat.simple_format/2
Summary
Functions
Rail’s simple_format helper for Phoenix.HTML
Functions
Rail’s simple_format helper for Phoenix.HTML
Returns text transformed into HTML using simple formatting rules.
Two or more consecutive newlines \n\n
are considered as a paragraph
and wrapped in <p>
tags. One newline \n
is considered as a linebreak
and a <br>
tag is appended.
Usage
In the view:
import SimpleFormat
In the template:
<%= simple_format @message %>
Examples
iex> SimpleFormat.simple_format("Hello\n\nWorld") |> Phoenix.HTML.safe_to_string
"<p>Hello</p>\n<p>World</p>\n"
iex> SimpleFormat.simple_format("Hello\nWorld") |> Phoenix.HTML.safe_to_string
"<p>Hello<br>\nWorld</p>\n"
iex> opts = [wrapper_tag: :div, attributes: [class: "p"]]
...> SimpleFormat.simple_format("Hello\n\nWorld", opts) |> Phoenix.HTML.safe_to_string
"<div class=\"p\">Hello</div>\n<div class=\"p\">World</div>\n"
Options
:escape
- if false does not html escape input (default:true
):wrapper_tag
- tag to wrap each parapgraph (default::p
):attributes
- html attributes of the wrapper tag (default:[]
)