Skip to content

Commit

Permalink
Split echo and raw echo in blade
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Mar 18, 2024
1 parent 2a685b8 commit 4a8c2e8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Languages/Blade/Injections/BladeEchoInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public function getPattern(): string
{
return '({{|{!!)(?<match>.*)(}}|!!})';
return '({{)(?<match>.*)(}})';
}

public function parseContent(string $content, Highlighter $highlighter): string
Expand Down
24 changes: 24 additions & 0 deletions src/Languages/Blade/Injections/BladeRawEchoInjection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight\Languages\Blade\Injections;

use Tempest\Highlight\Highlighter;
use Tempest\Highlight\Injection;
use Tempest\Highlight\IsInjection;

final readonly class BladeRawEchoInjection implements Injection
{
use IsInjection;

public function getPattern(): string
{
return '({!!)(?<match>.*)(!!})';
}

public function parseContent(string $content, Highlighter $highlighter): string
{
return $highlighter->parse($content, 'php');
}
}
10 changes: 0 additions & 10 deletions tests/Languages/Blade/Injections/BladeEchoInjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,4 @@ public function test_injection(): void
expected: '{{ <span class="hl-property">count</span>($foo) }}',
);
}

#[Test]
public function test_injection_raw_echo(): void
{
$this->assertMatches(
injection: new BladeEchoInjection(),
content: '{!! count($foo) !!}',
expected: '{!! <span class="hl-property">count</span>($foo) !!}',
);
}
}
23 changes: 23 additions & 0 deletions tests/Languages/Blade/Injections/BladeRawEchoInjectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Tempest\Highlight\Tests\Languages\Blade\Injections;

use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use Tempest\Highlight\Languages\Blade\Injections\BladeRawEchoInjection;
use Tempest\Highlight\Tests\TestsInjections;

class BladeRawEchoInjectionTest extends TestCase
{
use TestsInjections;

#[Test]
public function test_injection_raw_echo(): void
{
$this->assertMatches(
injection: new BladeRawEchoInjection(),
content: '{!! count($foo) !!}',
expected: '{!! <span class="hl-property">count</span>($foo) !!}',
);
}
}

0 comments on commit 4a8c2e8

Please sign in to comment.