mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
implements a temporary workaround for failing notextile
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
module RailsGuides
|
||||
module TextileExtensions
|
||||
module TextileExtensions
|
||||
def notestuff(body)
|
||||
body.gsub!(/^(IMPORTANT|CAUTION|WARNING|NOTE|INFO)(?:\.|\:)(.*)$/) do |m|
|
||||
css_class = $1.downcase
|
||||
@@ -31,7 +31,7 @@ module RailsGuides
|
||||
end
|
||||
|
||||
def code(body)
|
||||
body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql)>(.*?)</\1>}m) do |m|
|
||||
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
|
||||
%{<notextile><div class="code_container"><code class="#{css_class}">#{es}</code></div></notextile>}
|
||||
|
||||
Reference in New Issue
Block a user