From ecd2f3af59cc4670922cc71ccc94797c14b587f5 Mon Sep 17 00:00:00 2001 From: matthes Date: Thu, 2 Nov 2017 15:32:45 +0100 Subject: [PATCH] Replace linebreaks in lines consisting only of arguments --- src/TextTemplate.php | 11 ++++++++--- test/unit/tpls/06_debug_vars/out.txt | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/TextTemplate.php b/src/TextTemplate.php index 23ace95..00a0796 100644 --- a/src/TextTemplate.php +++ b/src/TextTemplate.php @@ -224,9 +224,14 @@ private function _removeComments ($input) { private function _removeWhitespace ($input) { - //echo $input; - $input = preg_replace("/\}\s*\{(?!=)/im", "}{", $input); - //echo $input; + // Replace: All lines + // - Starting with Newline and optional spaces + // - With only {xyz} + // - Not Starting with {= + // And ending with newline by single line + // + // Caution: Lookahead at the end required to strip multiple lines! + $input = preg_replace("/\\n\s*(\{(?!\=)[^\}]+?\})(?=[\\n\{])/m", '$1', $input); return $input; } diff --git a/test/unit/tpls/06_debug_vars/out.txt b/test/unit/tpls/06_debug_vars/out.txt index e9ba080..76408ad 100644 --- a/test/unit/tpls/06_debug_vars/out.txt +++ b/test/unit/tpls/06_debug_vars/out.txt @@ -1,4 +1,5 @@ 1: Start + ----- __CONTEXT__ ----- array ( 'boolVal' => true,