mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
do not assume code blocks have blank lines around, also nontextile -> notextile
This commit is contained in:
parent
f6fbdf39d7
commit
eb472d6d21
1 changed files with 5 additions and 5 deletions
|
@ -109,8 +109,8 @@ module RailsGuides
|
|||
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)
|
||||
|
@ -120,18 +120,18 @@ module RailsGuides
|
|||
# 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
|
||||
|
|
Loading…
Reference in a new issue