提交 4b33fae1 编写于 作者: D David Heinemeier Hansson

Fixed RedCloth and BlueCloth shouldn't preload. Instead just assume that...

Fixed RedCloth and BlueCloth shouldn't preload. Instead just assume that they're available if you want to use textilize and markdown and let autoload require them [DHH]
上级 54c18564
*2.3.0/3.0*
* Fixed RedCloth and BlueCloth shouldn't preload. Instead just assume that they're available if you want to use textilize and markdown and let autoload require them [DHH]
*2.2.1 [RC2] (November 14th, 2008)* *2.2.1 [RC2] (November 14th, 2008)*
* Restore backwards compatible functionality for setting relative_url_root. Include deprecation * Restore backwards compatible functionality for setting relative_url_root. Include deprecation
......
...@@ -226,91 +226,79 @@ def word_wrap(text, *args) ...@@ -226,91 +226,79 @@ def word_wrap(text, *args)
end * "\n" end * "\n"
end end
begin # Returns the text with all the Textile[http://www.textism.com/tools/textile] codes turned into HTML tags.
require_library_or_gem "redcloth" unless Object.const_defined?(:RedCloth) #
# You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile].
# Returns the text with all the Textile[http://www.textism.com/tools/textile] codes turned into HTML tags. # <i>This method is only available if RedCloth[http://whytheluckystiff.net/ruby/redcloth/]
# # is available</i>.
# You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile]. #
# <i>This method is only available if RedCloth[http://whytheluckystiff.net/ruby/redcloth/] # ==== Examples
# is available</i>. # textilize("*This is Textile!* Rejoice!")
# # # => "<p><strong>This is Textile!</strong> Rejoice!</p>"
# ==== Examples #
# textilize("*This is Textile!* Rejoice!") # textilize("I _love_ ROR(Ruby on Rails)!")
# # => "<p><strong>This is Textile!</strong> Rejoice!</p>" # # => "<p>I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!</p>"
# #
# textilize("I _love_ ROR(Ruby on Rails)!") # textilize("h2. Textile makes markup -easy- simple!")
# # => "<p>I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!</p>" # # => "<h2>Textile makes markup <del>easy</del> simple!</h2>"
# #
# textilize("h2. Textile makes markup -easy- simple!") # textilize("Visit the Rails website "here":http://www.rubyonrails.org/.)
# # => "<h2>Textile makes markup <del>easy</del> simple!</h2>" # # => "<p>Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>.</p>"
# def textilize(text)
# textilize("Visit the Rails website "here":http://www.rubyonrails.org/.) if text.blank?
# # => "<p>Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>.</p>" ""
def textilize(text) else
if text.blank? textilized = RedCloth.new(text, [ :hard_breaks ])
"" textilized.hard_breaks = true if textilized.respond_to?(:hard_breaks=)
else textilized.to_html
textilized = RedCloth.new(text, [ :hard_breaks ])
textilized.hard_breaks = true if textilized.respond_to?(:hard_breaks=)
textilized.to_html
end
end end
end
# Returns the text with all the Textile codes turned into HTML tags, # Returns the text with all the Textile codes turned into HTML tags,
# but without the bounding <p> tag that RedCloth adds. # but without the bounding <p> tag that RedCloth adds.
# #
# You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile]. # You can learn more about Textile's syntax at its website[http://www.textism.com/tools/textile].
# <i>This method is only available if RedCloth[http://whytheluckystiff.net/ruby/redcloth/] # <i>This method is requires RedCloth[http://whytheluckystiff.net/ruby/redcloth/]
# is available</i>. # to be available</i>.
# #
# ==== Examples # ==== Examples
# textilize_without_paragraph("*This is Textile!* Rejoice!") # textilize_without_paragraph("*This is Textile!* Rejoice!")
# # => "<strong>This is Textile!</strong> Rejoice!" # # => "<strong>This is Textile!</strong> Rejoice!"
# #
# textilize_without_paragraph("I _love_ ROR(Ruby on Rails)!") # textilize_without_paragraph("I _love_ ROR(Ruby on Rails)!")
# # => "I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!" # # => "I <em>love</em> <acronym title="Ruby on Rails">ROR</acronym>!"
# #
# textilize_without_paragraph("h2. Textile makes markup -easy- simple!") # textilize_without_paragraph("h2. Textile makes markup -easy- simple!")
# # => "<h2>Textile makes markup <del>easy</del> simple!</h2>" # # => "<h2>Textile makes markup <del>easy</del> simple!</h2>"
# #
# textilize_without_paragraph("Visit the Rails website "here":http://www.rubyonrails.org/.) # textilize_without_paragraph("Visit the Rails website "here":http://www.rubyonrails.org/.)
# # => "Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>." # # => "Visit the Rails website <a href="http://www.rubyonrails.org/">here</a>."
def textilize_without_paragraph(text) def textilize_without_paragraph(text)
textiled = textilize(text) textiled = textilize(text)
if textiled[0..2] == "<p>" then textiled = textiled[3..-1] end if textiled[0..2] == "<p>" then textiled = textiled[3..-1] end
if textiled[-4..-1] == "</p>" then textiled = textiled[0..-5] end if textiled[-4..-1] == "</p>" then textiled = textiled[0..-5] end
return textiled return textiled
end
rescue LoadError
# We can't really help what's not there
end end
begin # Returns the text with all the Markdown codes turned into HTML tags.
require_library_or_gem "bluecloth" unless Object.const_defined?(:BlueCloth) # <i>This method requires BlueCloth[http://www.deveiate.org/projects/BlueCloth]
# to be available</i>.
# Returns the text with all the Markdown codes turned into HTML tags. #
# <i>This method is only available if BlueCloth[http://www.deveiate.org/projects/BlueCloth] # ==== Examples
# is available</i>. # markdown("We are using __Markdown__ now!")
# # # => "<p>We are using <strong>Markdown</strong> now!</p>"
# ==== Examples #
# markdown("We are using __Markdown__ now!") # markdown("We like to _write_ `code`, not just _read_ it!")
# # => "<p>We are using <strong>Markdown</strong> now!</p>" # # => "<p>We like to <em>write</em> <code>code</code>, not just <em>read</em> it!</p>"
# #
# markdown("We like to _write_ `code`, not just _read_ it!") # markdown("The [Markdown website](http://daringfireball.net/projects/markdown/) has more information.")
# # => "<p>We like to <em>write</em> <code>code</code>, not just <em>read</em> it!</p>" # # => "<p>The <a href="http://daringfireball.net/projects/markdown/">Markdown website</a>
# # # has more information.</p>"
# markdown("The [Markdown website](http://daringfireball.net/projects/markdown/) has more information.") #
# # => "<p>The <a href="http://daringfireball.net/projects/markdown/">Markdown website</a> # markdown('![The ROR logo](http://rubyonrails.com/images/rails.png "Ruby on Rails")')
# # has more information.</p>" # # => '<p><img src="http://rubyonrails.com/images/rails.png" alt="The ROR logo" title="Ruby on Rails" /></p>'
# def markdown(text)
# markdown('![The ROR logo](http://rubyonrails.com/images/rails.png "Ruby on Rails")') text.blank? ? "" : BlueCloth.new(text).to_html
# # => '<p><img src="http://rubyonrails.com/images/rails.png" alt="The ROR logo" title="Ruby on Rails" /></p>'
def markdown(text)
text.blank? ? "" : BlueCloth.new(text).to_html
end
rescue LoadError
# We can't really help what's not there
end end
# Returns +text+ transformed into HTML using simple formatting rules. # Returns +text+ transformed into HTML using simple formatting rules.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册