Skip to content

Commit

Permalink
CSS @import
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Apr 25, 2024
1 parent 25896d3 commit 38b63f0
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
2 changes: 2 additions & 0 deletions src/Languages/Css/CssLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Tempest\Highlight\Languages\Css\Patterns\CssAttributePattern;
use Tempest\Highlight\Languages\Css\Patterns\CssCommentPattern;
use Tempest\Highlight\Languages\Css\Patterns\CssFunctionPattern;
use Tempest\Highlight\Languages\Css\Patterns\CssImportPattern;
use Tempest\Highlight\Languages\Css\Patterns\CssMediaQueryPattern;
use Tempest\Highlight\Languages\Css\Patterns\CssSelectorPattern;
use Tempest\Highlight\Languages\Css\Patterns\CssVariablePattern;
Expand All @@ -31,6 +32,7 @@ public function getPatterns(): array
return [
...parent::getPatterns(),
new CssMediaQueryPattern(),
new CssImportPattern(),
new CssCommentPattern(),
new CssSelectorPattern(),
new CssAttributePattern(),
Expand Down
26 changes: 26 additions & 0 deletions src/Languages/Css/Patterns/CssImportPattern.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Tempest\Highlight\Languages\Css\Patterns;

use Tempest\Highlight\IsPattern;
use Tempest\Highlight\Pattern;
use Tempest\Highlight\PatternTest;
use Tempest\Highlight\Tokens\TokenTypeEnum;

#[PatternTest(input: "@import main.css", output: '@import')]
final readonly class CssImportPattern implements Pattern
{
use IsPattern;

public function getPattern(): string
{
return '(?<match>\@import)';
}

public function getTokenType(): TokenTypeEnum
{
return TokenTypeEnum::KEYWORD;
}
}
2 changes: 2 additions & 0 deletions tests/Languages/Css/CssLanguageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public static function data(): array
}
TXT,
],
['linear-gradient(', '<span class="hl-keyword">linear-gradient</span>('],
['@import "foo.css"', '<span class="hl-keyword">@import</span> &quot;foo.css&quot;'],
];
}
}
10 changes: 1 addition & 9 deletions tests/targets/test.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
```css
.reveal .code-wrapper code {
line-height: 150%;

background:

linear-gradient(
white 30%,
rgba(255, 255, 255, 0)
) center top,
@import "../../vendor/tempest/highlight/src/Themes/highlight-light-lite.css";
```

0 comments on commit 38b63f0

Please sign in to comment.