Skip to content

Commit

Permalink
Handle spaces around tag interpolations
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Feb 16, 2017
1 parent 99ae5cf commit 7049ade
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
10 changes: 0 additions & 10 deletions src/Jade/Compiler/TagVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,6 @@ protected function insertSpacesBetweenBlockNodes($nodes)
) {
$nodes[$i - 1]->value .= ' ';
}

if (
$nodes[$i] instanceof Text &&
$nodes[$i - 1] instanceof Block &&
$nodes[$i - 1]->nodes[0] instanceof Tag &&
!preg_match('/^\s/', $nodes[$i]->value) &&
!empty($nodes[$i]->value)
) {
$nodes[$i]->value = ' ' . $nodes[$i]->value;
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/Jade/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

class Parser
{
const INLINE_TAG = '/^(.*?)#\[([^\]\n]+)\]/';

public static $includeNotFound = '.alert.alert-danger Page not found.';

protected $allowMixedIndent;
Expand Down Expand Up @@ -252,7 +254,7 @@ protected function parseExpression()
protected function parseText()
{
$token = $this->expect('text');
if (preg_match('/^(.*?)#\[([^\]\n]+)\]/', $token->value)) {
if (preg_match(static::INLINE_TAG, $token->value)) {
$block = new Nodes\Block();
$this->parseInlineTags($block, $token->value);

Expand Down Expand Up @@ -629,7 +631,9 @@ protected function parseTag()

public function parseInlineTags($block, $str)
{
while (preg_match('/^(.*?)#\[([^\]\n]+)\]/', $str, $matches)) {
$removeWhiteSpace = substr($str, 0, 1) === ' ';
while (preg_match(static::INLINE_TAG, $str, $matches)) {
$removeWhiteSpace = false;
if (!empty($matches[1])) {
$text = new Nodes\Text($matches[1]);
$text->line = $this->line();
Expand All @@ -641,7 +645,7 @@ public function parseInlineTags($block, $str)
$block->push($tag);
$str = substr($str, strlen($matches[0]));
}
if (substr($str, 0, 1) === ' ') {
if ($removeWhiteSpace) {
$str = substr($str, 1);
}
$text = new Nodes\Text($str);
Expand Down

0 comments on commit 7049ade

Please sign in to comment.