Skip to content

Commit

Permalink
fix: dont assume that all themes will highlight a token
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangjchandler committed Nov 5, 2024
1 parent 1544ccc commit c5c83cc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion resources/samples/sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

$sample = file_get_contents(__DIR__.'/'.$grammar.'.sample');
$tokens = (new Phiki($environment))->codeToTokens($sample, $grammar);
$html = (new Phiki($environment))->codeToHtml($sample, $grammar, ['light' => Theme::GithubLight, 'dark' => 'github-dark']);
$html = (new Phiki($environment))->codeToHtml($sample, $grammar, ['light' => Theme::OneLight, 'dark' => 'github-dark']);

?>

Expand Down
6 changes: 3 additions & 3 deletions src/Generators/HtmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public function generate(array $tokens): string
}

$tokenStyles = [
$token->settings[$defaultThemeId]->toStyleString(),
($token->settings[$defaultThemeId] ?? null)?->toStyleString(),
];

foreach ($token->settings as $id => $settings) {
if ($settings === $token->settings[$defaultThemeId]) {
if ($id === $defaultThemeId) {
continue;
}

Expand All @@ -108,7 +108,7 @@ public function generate(array $tokens): string

$html[] = sprintf(
'<span class="token" style="%s">%s</span>',
implode(';', $tokenStyles),
implode(';', array_filter($tokenStyles)),
htmlspecialchars($token->token->text),
);
}
Expand Down

0 comments on commit c5c83cc

Please sign in to comment.