module ActionView::Helpers::TextHelper
def simple_format(text, html_options = {}, options = {})
It's true.
"simple_format(" It's true.", {}, sanitize: false)
# => "
Unblinkable.
"simple_format("")
# => "
Look ma! A class!
"simple_format("Look ma! A class!", class: 'description')
# => "
We want to put a paragraph...
\n\n...right there.
"simple_format(more_text)
more_text = "We want to put a paragraph...\n\n...right there."
# => "
Here is some basic text...\n
...with a line break.
"...with a line break.
simple_format(my_text, {}, wrapper_tag: "div")
# => "
Here is some basic text...\n
...with a line break.
simple_format(my_text)
my_text = "Here is some basic text...\n...with a line break."
==== Examples
* :wrapper_tag - String representing the wrapper tag, defaults to "p"
* :sanitize - If +false+, does not sanitize +text+.
==== Options
will be added to all created paragraphs.
You can pass any HTML attributes into html_options. These
newlines from the +text+.
tag is appended. This method does not remove the
(\n or \r\n) is considered a linebreak and a
considered a paragraph and wrapped in
tags. One newline
Two or more consecutive newlines (\n\n or \r\n\r\n) are
Returns +text+ transformed into HTML using simple formatting rules.
def simple_format(text, html_options = {}, options = {}) wrapper_tag = options.fetch(:wrapper_tag, :p) text = sanitize(text) if options.fetch(:sanitize, true) paragraphs = split_paragraphs(text) if paragraphs.empty? content_tag(wrapper_tag, nil, html_options) else paragraphs.map! { |paragraph| content_tag(wrapper_tag, raw(paragraph), html_options) }.join("\n\n").html_safe end end