From 0d145d9b37a224955f2bbd346376988358966dde Mon Sep 17 00:00:00 2001 From: Xavier Noria Date: Sat, 28 Feb 2009 17:07:46 +0100 Subject: implements a temporary workaround for failing notextile --- railties/guides/rails_guides/generator.rb | 30 +++++++++++++++++++--- railties/guides/rails_guides/textile_extensions.rb | 4 +-- 2 files changed, 28 insertions(+), 6 deletions(-) (limited to 'railties/guides') diff --git a/railties/guides/rails_guides/generator.rb b/railties/guides/rails_guides/generator.rb index 085605a0d4..18fdb81810 100644 --- a/railties/guides/rails_guides/generator.rb +++ b/railties/guides/rails_guides/generator.rb @@ -109,11 +109,33 @@ module RailsGuides end def textile(body) - t = RedCloth.new(body) - t.hard_breaks = false - t.to_html(:notestuff, :plusplus, :code, :tip) + # If the issue with nontextile is fixed just remove the wrapper. + with_workaround_for_nontextile(body) do |body| + t = RedCloth.new(body) + t.hard_breaks = false + t.to_html(:notestuff, :plusplus, :code, :tip) + end + end + + # For some reason the notextile tag does not always turn off textile. See + # LH ticket of the security guide (#7). As a temporary workaround we deal + # with code blocks by hand. + def with_workaround_for_nontextile(body) + code_blocks = [] + body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)}m) do |m| + es = ERB::Util.h($2) + css_class = ['erb', 'shell'].include?($1) ? 'html' : $1 + code_blocks << %{
#{es}
} + "dirty_workaround_for_nontextile_#{code_blocks.size - 1}" + end + + body = yield body + + body.gsub(%r{

dirty_workaround_for_nontextile_(\d+)

}) do |_| + code_blocks[$1.to_i] + end end - + def warn_about_broken_links(html) # Textile generates headers with IDs computed from titles. anchors = Set.new(html.scan(/(.*?)}m) do |m| + body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)}m) do |m| es = ERB::Util.h($2) css_class = ['erb', 'shell'].include?($1) ? 'html' : $1 %{
#{es}
} -- cgit v1.2.3