aboutsummaryrefslogtreecommitdiffstats
path: root/railties/guides/rails_guides/generator.rb
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2009-02-28 17:07:46 +0100
committerXavier Noria <fxn@hashref.com>2009-02-28 17:07:46 +0100
commit0d145d9b37a224955f2bbd346376988358966dde (patch)
tree12d79d71e1dfdf344a65742e91d271aa77a15c6b /railties/guides/rails_guides/generator.rb
parent1108bd7fe9b7a474b244dead8944a4b0d34fba89 (diff)
downloadrails-0d145d9b37a224955f2bbd346376988358966dde.tar.gz
rails-0d145d9b37a224955f2bbd346376988358966dde.tar.bz2
rails-0d145d9b37a224955f2bbd346376988358966dde.zip
implements a temporary workaround for failing notextile
Diffstat (limited to 'railties/guides/rails_guides/generator.rb')
-rw-r--r--railties/guides/rails_guides/generator.rb30
1 files changed, 26 insertions, 4 deletions
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)>(.*?)</\1>}m) do |m|
+ es = ERB::Util.h($2)
+ css_class = ['erb', 'shell'].include?($1) ? 'html' : $1
+ code_blocks << %{<div class="code_container"><code class="#{css_class}">#{es}</code></div>}
+ "dirty_workaround_for_nontextile_#{code_blocks.size - 1}"
+ end
+
+ body = yield body
+
+ body.gsub(%r{<p>dirty_workaround_for_nontextile_(\d+)</p>}) 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(/<h\d\s+id="([^"]+)/).flatten)