Module: Textilize::Helper
- Defined in:
- lib/textilize/helper.rb
Instance Method Summary collapse
-
#textilize(text, *options) ⇒ Object
Returns the text with all the Textile codes turned into HTML tags.
-
#textilize_without_paragraph(text, *options) ⇒ Object
Returns the text with all the Textile codes turned into HTML tags, but without the bounding
tag that RedCloth adds.
Instance Method Details
#textilize(text, *options) ⇒ Object
Returns the text with all the Textile codes turned into HTML tags.
You can learn more about Textile's syntax at its website. This method is only available if RedCloth is available.
Examples
textilize("This is Textile! Rejoice!")
=> "
This is Textile! Rejoice!
"textilize("I _love_ ROR(Ruby on Rails)!")
# => "<p>I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!</p>"
textilize("h2. Textile makes markup -easy- simple!")
# => "<h2>Textile makes markup <del>easy</del> simple!</h2>"
textilize("Visit the Rails website "here":http://www.rubyonrails.org/.)
# => "<p>Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>.</p>"
textilize("This is worded <strong>strongly</strong>")
# => "<p>This is worded <strong>strongly</strong></p>"
textilize("This is worded <strong>strongly</strong>", :filter_html)
# => "<p>This is worded <strong>strongly</strong></p>"
30 31 32 33 |
# File 'lib/textilize/helper.rb', line 30 def textilize(text, *) text = sanitize(text) unless text.html_safe? text.blank? ? "" : RedCloth.new(text, ).to_html.html_safe end |
#textilize_without_paragraph(text, *options) ⇒ Object
Returns the text with all the Textile codes turned into HTML tags, but without the bounding
tag that RedCloth adds.
You can learn more about Textile's syntax at its website. This method is requires RedCloth to be available.
Examples
textilize_without_paragraph("This is Textile! Rejoice!")
=> "This is Textile! Rejoice!"
textilize_without_paragraph("I _love_ ROR(Ruby on Rails)!")
# => "I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!"
textilize_without_paragraph("h2. Textile makes markup -easy- simple!")
# => "<h2>Textile makes markup <del>easy</del> simple!</h2>"
textilize_without_paragraph("Visit the Rails website "here":http://www.rubyonrails.org/.)
# => "Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>."
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/textilize/helper.rb', line 54 def textilize_without_paragraph(text, *) textiled = textilize(text, *) if textiled[0..2] == "<p>" textiled = textiled[3..-1] end if textiled[-4..-1] == "</p>" textiled = textiled[0..-5] end textiled.html_safe end |