Skip to content

Commit

Permalink
do not assume code blocks have blank lines around, also nontextile ->…
Browse files Browse the repository at this point in the history
… notextile
  • Loading branch information
fxn committed Mar 2, 2009
1 parent f6fbdf3 commit eb472d6
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions railties/guides/rails_guides/generator.rb
Expand Up @@ -109,8 +109,8 @@ def set_index(body, view)
end

def textile(body)
# If the issue with nontextile is fixed just remove the wrapper.
with_workaround_for_nontextile(body) do |body|
# If the issue with notextile is fixed just remove the wrapper.
with_workaround_for_notextile(body) do |body|
t = RedCloth.new(body)
t.hard_breaks = false
t.to_html(:notestuff, :plusplus, :code, :tip)
Expand All @@ -120,18 +120,18 @@ def textile(body)
# 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)
def with_workaround_for_notextile(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}"
"\ndirty_workaround_for_notextile_#{code_blocks.size - 1}\n"
end

body = yield body

body.gsub(%r{<p>dirty_workaround_for_nontextile_(\d+)</p>}) do |_|
body.gsub(%r{<p>dirty_workaround_for_notextile_(\d+)</p>}) do |_|
code_blocks[$1.to_i]
end
end
Expand Down

0 comments on commit eb472d6

Please sign in to comment.