summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-10-25 00:17:53 +0200
committerKevin Chabowski <kevin@kch42.de>2013-10-25 00:17:53 +0200
commit80c76caffa50ce7c9a520ff2773d1c98b9100875 (patch)
treefe3535263583e750932ed9f5acbf04b0b59d8cd8
parentecb1ed97be62f26e84d860f3b79244237947aab5 (diff)
downloadste-80c76caffa50ce7c9a520ff2773d1c98b9100875.tar.gz
ste-80c76caffa50ce7c9a520ff2773d1c98b9100875.tar.bz2
ste-80c76caffa50ce7c9a520ff2773d1c98b9100875.zip
Better handling of newslines and whitespaces
-rw-r--r--stupid_template_engine.php30
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;
}