Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Commit

Permalink
Cleanup regexes
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexVanderbist committed Oct 7, 2018
1 parent 44dd120 commit d0a2379
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 7 additions & 11 deletions src/BladeXCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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*(?<attributes>.*)\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);
Expand All @@ -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}(?<attributes>(?:\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);
Expand All @@ -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);
}
Expand Down

0 comments on commit d0a2379

Please sign in to comment.