From 09f57124f911e17fb15a48a0d18f500b8efe1283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 3 Dec 2008 01:42:47 +0100 Subject: [PATCH] strip leading whitespace in generated code blocks --- lib/hanna/template_files/page.haml | 2 +- lib/hanna/template_helpers.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/hanna/template_files/page.haml b/lib/hanna/template_files/page.haml index 41a4f15..6e2778b 100644 --- a/lib/hanna/template_files/page.haml +++ b/lib/hanna/template_files/page.haml @@ -45,6 +45,6 @@ #text - if values["description"] - #description~ values["description"] + #description~ sanitize_code_blocks values["description"] = yield diff --git a/lib/hanna/template_helpers.rb b/lib/hanna/template_helpers.rb index d4bb7b5..475c5cf 100644 --- a/lib/hanna/template_helpers.rb +++ b/lib/hanna/template_helpers.rb @@ -104,5 +104,10 @@ def render_class_tree(tree, parent = nil) out end end + + # primarily for removing leading whitespace in
 tags
+    def sanitize_code_blocks(text)
+      text.gsub(/
(.+?)<\/pre>/m) { "
#{$1.sub(/^\s*\n/, '')}
" } + end end end