From 0dfee8331bb54c39e5b25a2de856a0e3651042ad Mon Sep 17 00:00:00 2001 From: franck Date: Wed, 17 Jul 2013 11:34:48 +0200 Subject: [PATCH] Added an output filter to remove blank lines from generated HTML --- .../lib/Thelia/Core/Template/Smarty/SmartyParser.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php index 8e34a89ed..4f1060055 100755 --- a/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php +++ b/core/lib/Thelia/Core/Template/Smarty/SmartyParser.php @@ -74,14 +74,20 @@ class SmartyParser extends Smarty implements ParserInterface $this->status = 200; $this->registerFilter('pre', array($this, "preThelia")); + $this->registerFilter('output', array($this, "removeBlankLines")); } public function preThelia($tpl_source, \Smarty_Internal_Template $template) { - $new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9\-_]*)(.*)}`', '{\$$1$2}', $tpl_source); - $new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9\-_]*)`', '{\$$1|dieseCanceller:\'#$1\'}', $new_source); + $new_source = preg_replace('`{#([a-zA-Z][a-zA-Z0-9\-_]*)(.*)}`', '{\$$1$2}', $tpl_source); + $new_source = preg_replace('`#([a-zA-Z][a-zA-Z0-9\-_]*)`', '{\$$1|dieseCanceller:\'#$1\'}', $new_source); - return $new_source; + return $new_source; + } + + public function removeBlankLines($tpl_source, \Smarty_Internal_Template $template) + { + return preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $tpl_source); } public function setTemplate($template_path_from_template_base)