diff --git a/README.md b/README.md index a69a673..67e4e8f 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ The package will automatically register itself. ## Usage -A the contents of a component can be stored in a simple Blade view. +The contents of a component can be stored in a simple Blade view. ```blade {{-- resources/views/components/myAlert.blade.php --}} diff --git a/src/BladeXCompiler.php b/src/BladeXCompiler.php index 6ba842e..0519c94 100644 --- a/src/BladeXCompiler.php +++ b/src/BladeXCompiler.php @@ -24,10 +24,10 @@ public function compile(string $viewContents): string protected function parseComponentHtml(string $viewContents, BladeXComponent $bladeXComponent) { - $pattern = "/<\s*{$bladeXComponent->name}[^>]*>((.|\n)*?)<\s*\/\s*{$bladeXComponent->name}>/m"; + $pattern = "/<\s*{$bladeXComponent->name}[^>]*(?:\/>|>((?:.|\n)*?)<\s*\/\s*{$bladeXComponent->name}>)/m"; return preg_replace_callback($pattern, function (array $regexResult) use ($bladeXComponent) { - [$componentHtml, $componentInnerHtml] = $regexResult; + [$componentHtml, $componentInnerHtml] = $regexResult + ['', '']; return "@component('{$bladeXComponent->bladeViewName}', [{$this->getComponentAttributes($componentHtml)}])" .$this->parseComponentInnerHtml($componentInnerHtml)