method
simple_format
v7.1.3.4 -
Show latest stable
-
0 notes -
Class: ActionView::Helpers::TextHelper
- 1.0.0 (0)
- 1.1.6 (-1)
- 1.2.6 (-1)
- 2.0.3 (38)
- 2.1.0 (19)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (0)
- 3.0.9 (-4)
- 3.1.0 (20)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (27)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (3)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (29)
- 7.1.3.4 (0)
- What's this?
simple_format(text, html_options = {}, options = {})
public
Returns text transformed into HTML using simple formatting rules. Two or more consecutive newlines (\n\n or \r\n\r\n) are considered a paragraph and wrapped in <p> tags. One newline (\n or \r\n) is considered a linebreak and a <br /> tag is appended. This method does not remove the newlines from the text.
You can pass any HTML attributes into html_options. These will be added to all created paragraphs.
Options
-
:sanitize_options - Any extra options you want appended to the sanitize.
-
:wrapper_tag - String representing the wrapper tag, defaults to "p"
Examples
my_text = "Here is some basic text...\n...with a line break." simple_format(my_text) # => "<p>Here is some basic text...\n<br />...with a line break.</p>" simple_format(my_text, {}, wrapper_tag: "div") # => "<div>Here is some basic text...\n<br />...with a line break.</div>" more_text = "We want to put a paragraph...\n\n...right there." simple_format(more_text) # => "<p>We want to put a paragraph...</p>\n\n<p>...right there.</p>" simple_format("Look ma! A class!", class: 'description') # => "<p class='description'>Look ma! A class!</p>" simple_format("<blink>Unblinkable.</blink>") # => "<p>Unblinkable.</p>" simple_format("<blink>Blinkable!</blink> It's true.", {}, sanitize: false) # => "<p><blink>Blinkable!</blink> It's true.</p>" simple_format("<a target=\"_blank\" href=\"http://example.com\">Continue</a>", {}, { sanitize_options: { attributes: %w[target href] } }) # => "<p><a target=\"_blank\" href=\"http://example.com\">Continue</a></p>"