Skip to content

Commit

Permalink
BaseLanguage as the default
Browse files Browse the repository at this point in the history
  • Loading branch information
brendt committed Mar 25, 2024
1 parent d108d8a commit cde9a72
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
9 changes: 2 additions & 7 deletions src/Highlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tempest\Highlight;

use Tempest\Highlight\Languages\Base\BaseLanguage;
use Tempest\Highlight\Languages\Blade\BladeLanguage;
use Tempest\Highlight\Languages\Css\CssLanguage;
use Tempest\Highlight\Languages\DocComment\DocCommentLanguage;
Expand Down Expand Up @@ -54,13 +55,7 @@ public function setLanguage(string $name, Language $language): self
public function parse(string $content, string|Language $language): string
{
if (is_string($language)) {
$language = $this->languages[$language] ?? null;
}

if (! $language) {
return $this->shouldEscape ?
Escape::html($content)
: $content;
$language = $this->languages[$language] ?? new BaseLanguage();
}

$this->currentLanguage = $language;
Expand Down
13 changes: 10 additions & 3 deletions tests/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
}

.hl {
width: 800px;
margin: 3em auto;
box-shadow: 0 0 10px 0 #00000044;
padding: 1em 2em;
Expand All @@ -62,11 +61,19 @@
.hl-injection {
background-color: #00ffff22;
}

.container {
display: flex;
align-items: center;
height: 100vh;
}
</style>
</head>
<body>
<div class="hl">
<?= $contents ?>
<div class="container">
<div class="hl">
<?= $contents ?>
</div>
</div>
</body>
</html>
11 changes: 7 additions & 4 deletions tests/targets/test.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
```php
public function warning(
string|\Stringable $message,
array $context = []
): void;
(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\
\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[
^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(
?: \r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t
])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:
(?:( ?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\]\000-\0 31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\ ](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\]\000-\031]+ (?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?: (?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z |(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n) ?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\ r\n)?[ \t])+|\
```

0 comments on commit cde9a72

Please sign in to comment.