diff options
author | Kevin Chabowski <kevin@kch42.de> | 2013-10-25 00:17:53 +0200 |
---|---|---|
committer | Kevin Chabowski <kevin@kch42.de> | 2013-10-25 00:17:53 +0200 |
commit | 80c76caffa50ce7c9a520ff2773d1c98b9100875 (patch) | |
tree | fe3535263583e750932ed9f5acbf04b0b59d8cd8 /stupid_template_engine.php | |
parent | ecb1ed97be62f26e84d860f3b79244237947aab5 (diff) | |
download | ste-80c76caffa50ce7c9a520ff2773d1c98b9100875.tar.gz ste-80c76caffa50ce7c9a520ff2773d1c98b9100875.tar.bz2 ste-80c76caffa50ce7c9a520ff2773d1c98b9100875.zip |
Better handling of newslines and whitespaces
Diffstat (limited to 'stupid_template_engine.php')
-rw-r--r-- | stupid_template_engine.php | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/stupid_template_engine.php b/stupid_template_engine.php index 58b327d..0eef489 100644 --- a/stupid_template_engine.php +++ b/stupid_template_engine.php @@ -243,23 +243,26 @@ class Parser { $out = array(); $prevtext = NULL; - $wastag = true; + $first = true; + foreach($ast as $node) { if($node instanceof TextNode) { - if($wastag) { - $node->text = ltrim($node->text); - } - if($prevtext === NULL) { $prevtext = $node; } else { $prevtext->text .= $node->text; } } else { - if(($prevtext !== NULL) && ($prevtext->text != "")) { - $out[] = $prevtext; + if($prevtext !== NULL) { + if($first) { + $prevtext->text = ltrim($prevtext->text); + } + if($prevtext->text != "") { + $out[] = $prevtext; + } } $prevtext = NULL; + $first = false; if($node instanceof TagNode) { $node->sub = self::tidyup_ast($node->sub); @@ -273,15 +276,20 @@ class Parser { } unset($v); } + $out[] = $node; } - - $wastag = $node instanceof TagNode; } - if(($prevtext !== NULL) && ($prevtext->text != "")) { - $out[] = $prevtext; + if($prevtext !== NULL) { + if($first) { + $prevtext->text = ltrim($prevtext->text); + } + if($prevtext->text != "") { + $out[] = $prevtext; + } } + return $out; } |