Module: Textilize::Helper

Defined in:
lib/textilize/helper.rb

Instance Method Summary collapse

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[http://whytheluckystiff.net/ruby/redcloth/] is available.

Examples

textilize("*This is Textile!*  Rejoice!")
# => "<p><strong>This is Textile!</strong>  Rejoice!</p>"

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 &lt;strong&gt;strongly&lt;/strong&gt;</p>"


30
31
32
33
# File 'lib/textilize/helper.rb', line 30

def textilize(text, *options)
  text = sanitize(text) unless text.html_safe?
  text.blank? ? "" : RedCloth.new(text, options).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 <p> tag that RedCloth adds.

You can learn more about Textile’s syntax at its website. This method is requires RedCloth[http://whytheluckystiff.net/ruby/redcloth/] to be available.

Examples

textilize_without_paragraph("*This is Textile!*  Rejoice!")
# => "<strong>This is Textile!</strong>  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, *options)
  textiled = textilize(text, *options)
  if textiled[0..2] == "<p>" 
    textiled = textiled[3..-1] 
  end
  if textiled[-4..-1] == "</p>"
    textiled = textiled[0..-5] 
  end
  textiled.html_safe
end