Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Languages/Base/Patterns/AdditionEndTokenPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
use Tempest\Highlight\Tokens\TokenType;

#[PatternTest('{+ pull_request_target: +}', '+}')]
#[PatternTest('❷span class=❹ignore❹❸+}❷/span❸', null)]
final readonly class AdditionEndTokenPattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return '/(?<match>\+})/';
// A delimiter that is already ignored comes from code highlighted by a nested highlighter
return '/(?<!❹ignore❹❸)(?<match>\+})/';
}

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

#[PatternTest('{+ pull_request_target: +}', '{+')]
#[PatternTest('❷span class=❹ignore❹❸{+❷/span❸', null)]
final readonly class AdditionStartTokenPattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return '/(?<match>{\+)/';
// A delimiter that is already ignored comes from code highlighted by a nested highlighter
return '/(?<!❹ignore❹❸)(?<match>{\+)/';
}

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

#[PatternTest('{- pull_request_target: -}', '-}')]
#[PatternTest('❷span class=❹ignore❹❸-}❷/span❸', null)]
#[PatternTest('{-- pull_request_target: --}', null)]
#[PatternTest('{{- variable -}}', null)]
final readonly class DeletionEndTokenPattern implements Pattern
Expand All @@ -19,7 +20,8 @@

public function getPattern(): string
{
return '/(?<!-)(?<match>\-})(?!})/';
// A delimiter that is already ignored comes from code highlighted by a nested highlighter
return '/(?<!-)(?<!❹ignore❹❸)(?<match>\-})(?!})/';
}

public function getTokenType(): TokenType
Expand Down
4 changes: 3 additions & 1 deletion src/Languages/Base/Patterns/DeletionStartTokenPattern.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
#[PatternTest('{- pull_request_target: -}', '{-')]
#[PatternTest('{-- pull_request_target: --}', null)]
#[PatternTest('{{- variable -}}', null)]
#[PatternTest('❷span class=❹ignore❹❸{-❷/span❸', null)]
final readonly class DeletionStartTokenPattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return '/(?<!\{)(?<match>{\-)(?!-)/';
// A delimiter that is already ignored comes from code highlighted by a nested highlighter
return '/(?<!\{)(?<!❹ignore❹❸)(?<match>{\-)(?!-)/';
}

public function getTokenType(): TokenType
Expand Down
13 changes: 13 additions & 0 deletions tests/Languages/Base/Injections/AdditionInjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,17 @@ public function test_null_content_is_prevented(): void

$this->assertTrue(true);
}

public function test_addition_ending_inside_an_embedded_language(): void
{
$content = "{+<script>+}\n a;\n</script>";

$expected = <<<'TXT'
<span class="hl-addition">&lt;<span class="hl-keyword">script</span>&gt;</span>
a;
&lt;/<span class="hl-keyword">script</span>&gt;
TXT;

$this->assertSame($expected, (new Highlighter())->parse($content, 'html'));
}
}
13 changes: 13 additions & 0 deletions tests/Languages/Base/Injections/DeletionInjectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,17 @@ public function test_deletion_not_triggered_by_tag_whitespace_control()

$this->assertSame($content, $parsedInjection->content);
}

public function test_deletion_ending_inside_an_embedded_language(): void
{
$content = "{-<script>-}\n a;\n</script>";

$expected = <<<'TXT'
<span class="hl-deletion">&lt;<span class="hl-keyword">script</span>&gt;</span>
a;
&lt;/<span class="hl-keyword">script</span>&gt;
TXT;

$this->assertSame($expected, (new Highlighter())->parse($content, 'html'));
}
}
Loading