// push the template text first
$text = $textContent = substr($this->code, $this->cursor, $pos - $this->cursor);
if (true === $trimBlock) {
- $text = rtrim($text, " \t");
+ $text = rtrim($text);
}
$this->pushToken(Twig_Token::TEXT_TYPE, $text);
$this->moveCursor($textContent . $token . $append);
switch ($token) {
case $this->options['tag_comment'][0]:
$commentEndRegex = '/.*?(?:' . preg_quote($this->options['whitespace_trim'], '/')
- . preg_quote($this->options['tag_comment'][1], '/') . '\h*|'
+ . preg_quote($this->options['tag_comment'][1], '/') . '\s*|'
. preg_quote($this->options['tag_comment'][1], '/') . ')\n?/As';
if (!preg_match($commentEndRegex, $this->code, $match, null, $this->cursor)) {
$trimTag = preg_quote($this->options['whitespace_trim'] . $this->options['tag_block'][1], '/');
$endTag = preg_quote($this->options['tag_block'][1], '/');
- if (empty($this->brackets) && preg_match('/\s*(?:' . $trimTag . '\h*|\s*' . $endTag . ')\n?/A', $this->code, $match, null, $this->cursor)) {
+ if (empty($this->brackets) && preg_match('/\s*(?:' . $trimTag . '\s*|\s*' . $endTag . ')\n?/A', $this->code, $match, null, $this->cursor)) {
$this->pushToken(Twig_Token::BLOCK_END_TYPE);
$this->moveCursor($match[0]);
$this->state = self::STATE_DATA;
$trimTag = preg_quote($this->options['whitespace_trim'] . $this->options['tag_variable'][1], '/');
$endTag = preg_quote($this->options['tag_variable'][1], '/');
- if (empty($this->brackets) && preg_match('/\s*' . $trimTag . '\h*|\s*' . $endTag . '/A', $this->code, $match, null, $this->cursor)) {
+ if (empty($this->brackets) && preg_match('/\s*' . $trimTag . '\s*|\s*' . $endTag . '/A', $this->code, $match, null, $this->cursor)) {
$this->pushToken(Twig_Token::VAR_END_TYPE);
$this->moveCursor($match[0]);
$this->state = self::STATE_DATA;
--TEST--
Whitespace trimming on tags.
--TEMPLATE--
- {#- Comments can trim leading space #}
- <ul>
- {%- if leading %}
- <li> {{- leading }}</li>
- {%- endif %}
- </ul>
-
-{# Comments can trim trailing space -#}
- <ul>
- {%- if trailing -%}
- <li>{{ trailing -}} </li>
- {%- endif -%}
- </ul>
-
- <ul>
- {%- if mixed %}
- <li> {{- mixed }}</li>
- {% endif -%}
- </ul>
-
- {#- Comments can trim both -#}
- <ul>
- {%- if both -%}
- <li> {{- both -}} </li>
- {%- endif -%}
- </ul>
-after
{{ 5 * '{#-'|length }}
{{ '{{-'|length * 5 + '{%-'|length }}
+
+Trim on control tag:
+{% for i in range(1, 9) -%}
+ {{ i }}
+{%- endfor %}
+
+
+Trim on output tag:
+{% for i in range(1, 9) %}
+ {{- i -}}
+{% endfor %}
+
+
+Trim comments:
+
+{#- Invisible -#}
+
+After the comment.
+
+Trim leading space:
+{% if leading %}
+
+ {{- leading }}
+{% endif %}
+
+{%- if leading %}
+ {{- leading }}
+
+{%- endif %}
+
+
+Trim trailing space:
+{% if trailing -%}
+ {{ trailing -}}
+
+{% endif -%}
+
+Combined:
+
+{%- if both -%}
+<ul>
+ <li> {{- both -}} </li>
+</ul>
+
+{%- endif -%}
+
+end
--DATA--
-return array('leading' => 'leading space', 'trailing' => 'trailing tabs', 'mixed' => 'mixed tags', 'both' => 'both')
+return array('leading' => 'leading space', 'trailing' => 'trailing space', 'both' => 'both')
--EXPECT--
- <ul>
- <li>leading space</li>
- </ul>
-
- <ul>
- <li>trailing tabs</li>
- </ul>
-
- <ul>
- <li>mixed tags</li>
- </ul>
-
- <ul>
- <li>both</li>
- </ul>
-after
15
18
+
+Trim on control tag:
+123456789
+
+Trim on output tag:
+123456789
+
+Trim comments:After the comment.
+
+Trim leading space:
+leading space
+leading space
+
+Trim trailing space:
+trailing spaceCombined:<ul>
+ <li>both</li>
+</ul>end