diff --git a/CHANGELOG.md b/CHANGELOG.md index ebeed4a..25ac82c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ All notable changes to `laravel-blade-x` will be documented in this file -## 1.2.3 [wip] - 2018-10-07 +## 1.2.3 - 2018-10-07 - fix nested components and slots without spaces or on a single line - fix edge-case for slots with weird content diff --git a/src/BladeXCompiler.php b/src/BladeXCompiler.php index a05feea..2264284 100644 --- a/src/BladeXCompiler.php +++ b/src/BladeXCompiler.php @@ -38,12 +38,10 @@ protected function parseSelfClosingTags(string $viewContents, BladeXComponent $b { $prefix = $this->bladeX->getPrefix(); - $pattern = "/<\s*{$prefix}{$bladeXComponent->name}\s*(.*)\s*\/>/m"; + $pattern = "/<\s*{$prefix}{$bladeXComponent->name}\s*(?.*)\s*\/>/"; - return preg_replace_callback($pattern, function (array $regexResult) use ($bladeXComponent) { - [$componentHtml, $attributesString] = $regexResult; - - $attributes = $this->getAttributesFromAttributeString($attributesString); + return preg_replace_callback($pattern, function (array $matches) use ($bladeXComponent) { + $attributes = $this->getAttributesFromAttributeString($matches['attributes']); return $this->componentString($bladeXComponent, $attributes); }, $viewContents); @@ -53,12 +51,10 @@ protected function parseOpeningTags(string $viewContents, BladeXComponent $blade { $prefix = $this->bladeX->getPrefix(); - $pattern = "/<\s*{$prefix}{$bladeXComponent->name}((?:\s+[\w\-:]*=(?:\\\"(?:.*?)\\\"|\'(?:.*)\'|[^\'\\\"=<>]*))*\s*)(?/m"; - - return preg_replace_callback($pattern, function (array $regexResult) use ($bladeXComponent) { - [$componentHtml, $attributesString] = $regexResult; + $pattern = "/<\s*{$prefix}{$bladeXComponent->name}(?(?:\s+[\w\-:]+=(?:\\\"[^\\\"]+\\\"|\'[^\']+\'|[^\'\\\"=<>]+))*\s*)(?/"; - $attributes = $this->getAttributesFromAttributeString($attributesString); + return preg_replace_callback($pattern, function (array $matches) use ($bladeXComponent) { + $attributes = $this->getAttributesFromAttributeString($matches['attributes']); return $this->componentStartString($bladeXComponent, $attributes); }, $viewContents); @@ -68,7 +64,7 @@ protected function parseClosingTags(string $viewContents, BladeXComponent $blade { $prefix = $this->bladeX->getPrefix(); - $pattern = "/<\/\s*{$prefix}{$bladeXComponent->name}[^>]*>/m"; + $pattern = "/<\/\s*{$prefix}{$bladeXComponent->name}[^>]*>/"; return preg_replace($pattern, $this->componentEndString($bladeXComponent), $viewContents); }