SimplexFormat (simplex_format v0.2.0) View Source
Helpers related to formatting text.
Link to this section Summary
Functions
Returns text transformed into HTML using simple formatting rules.
Link to this section Functions
Specs
text_to_html(Phoenix.HTML.unsafe(), Keyword.t()) :: Phoenix.HTML.safe()
Returns text transformed into HTML using simple formatting rules.
Two or more consecutive newlines \n\n
or \r\n\r\n
are considered as a
paragraph and text between them is wrapped in <p>
tags.
One newline \n
or \r\n
is considered as a linebreak and a <br>
tag is inserted.
Examples
iex> text_to_html("Hello\n\nWorld") |> safe_to_string
"<p>Hello</p>\n<p>World</p>\n"
iex> text_to_html("Hello\nWorld") |> safe_to_string
"<p>Hello<br>\nWorld</p>\n"
iex> text_to_html("Hello, welcome to http://www.google.com", auto_link: true) |> safe_to_string
"<p>Hello, welcome to <a href=\"http://www.google.com\">http://www.google.com</a></p>\n"
iex> opts = [wrapper_tag: :div, attributes: [class: "p"]]
...> text_to_html("Hello\n\nWorld", opts) |> safe_to_string
"<div class=\"p\">Hello</div>\n<div class=\"p\">World</div>\n"
Options
:escape
- iffalse
does not html escape input (default:true
):wrapper_tag
- tag to wrap each paragraph (default::p
):attributes
- html attributes of the wrapper tag (default:[]
):insert_brs
- iftrue
insert<br>
for single line breaks (default:true
):auto_link
- iftrue
wrap HTTP URLs in an anchor tag (default:false
):url_attributes
- HTML attributes of the anchor tag for auto_linked URLs (default:[]
)