Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
teach #sanitize_code_blocks method to remove deep indent of code, too
Browse files Browse the repository at this point in the history
  • Loading branch information
mislav committed Dec 3, 2008
1 parent 266474f commit 4806ea2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/hanna/template_helpers.rb
Expand Up @@ -107,7 +107,13 @@ def render_class_tree(tree, parent = nil)

# primarily for removing leading whitespace in <pre> tags
def sanitize_code_blocks(text)
text.gsub(/<pre>(.+?)<\/pre>/m) { "<pre>#{$1.sub(/^\s*\n/, '')}</pre>" }
text.gsub(/<pre>(.+?)<\/pre>/m) do
code = $1.sub(/^\s*\n/, '')
indent = code.gsub(/\n[ \t]*\n/, "\n").scan(/^ */).map{ |i| i.size }.min
code.gsub!(/^#{' ' * indent}/, '') if indent > 0

"<pre>#{code}</pre>"
end
end
end
end

0 comments on commit 4806ea2

Please sign in to comment.