Skip to content

Commit

Permalink
Fix blade comments
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed May 2, 2024
1 parent 162a733 commit 6a2f9f7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Languages/Base/Injections/DeletionInjection.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function parse(string $content, Highlighter $highlighter): ParsedInjectio
$content = str_replace('❷span class=❹ignore❹❸{-❷/span❸', '{-', $content);
$content = str_replace('❷span class=❹ignore❹❸-}❷/span❸', '-}', $content);

preg_match_all('/(\{-)((.|\n)*?)(-})/', $content, $matches, PREG_OFFSET_CAPTURE);
preg_match_all('/(\{-)(?!-)((.|\n)*?)(-})/', $content, $matches, PREG_OFFSET_CAPTURE);

$parsedOffset = 0;

Expand Down
3 changes: 2 additions & 1 deletion src/Languages/Base/Patterns/DeletionEndTokenPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
use Tempest\Highlight\Tokens\TokenType;

#[PatternTest('{- pull_request_target: -}', '-}')]
#[PatternTest('{-- pull_request_target: --}', null)]
final readonly class DeletionEndTokenPattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return '/(?<match>\-})/';
return '/(?<!-)(?<match>\-})/';
}

public function getTokenType(): TokenType
Expand Down
3 changes: 2 additions & 1 deletion src/Languages/Base/Patterns/DeletionStartTokenPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
use Tempest\Highlight\Tokens\TokenType;

#[PatternTest('{- pull_request_target: -}', '{-')]
#[PatternTest('{-- pull_request_target: --}', null)]
final readonly class DeletionStartTokenPattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return '/(?<match>{\-)/';
return '/(?<match>{\-)(?!-)/';
}

public function getTokenType(): TokenType
Expand Down
30 changes: 30 additions & 0 deletions tests/Languages/Blade/BladeLanguageTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight\Tests\Languages\Blade;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Tempest\Highlight\Highlighter;

class BladeLanguageTest extends TestCase
{
#[DataProvider('data')]
public function test_highlight(string $content, string $expected): void
{
$highlighter = new Highlighter();

$this->assertSame(
$expected,
$highlighter->parse($content, 'blade'),
);
}

public static function data(): array
{
return [
['{{-- Blade comment --}}', '<span class="hl-comment">{{-- Blade comment --}}</span>'],
];
}
}
4 changes: 2 additions & 2 deletions tests/targets/test.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```php
self::$staticProperty;
```blade
{{-- Blade comment --}}
```

0 comments on commit 6a2f9f7

Please sign in to comment.