Skip to content

Commit

Permalink
Remove methods
Browse files Browse the repository at this point in the history
  • Loading branch information
riasvdv committed Feb 19, 2024
1 parent b6015fc commit cc1e021
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 91 deletions.
11 changes: 1 addition & 10 deletions bin/shiki.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ async function main(args) {

if (!customLanguages[language]) await highlighter.loadLanguage(language);

if (args[0] === 'languages') {
process.stdout.write(JSON.stringify(highlighter.getLoadedLanguages()));
return;
}

if (args[0] === 'themes') {
process.stdout.write(JSON.stringify(highlighter.getLoadedThemes()));
return;
}

const { theme: theme$ } = highlighter.setTheme(theme)

const result = highlighter.codeToTokens(args[0], {
Expand Down Expand Up @@ -76,6 +66,7 @@ function loadLanguage(language) {

return JSON.parse(content);
}

function getLanguagePath(language) {
const url = path.join(__dirname, '..', 'languages', `${language}.tmLanguage.json`);

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
}
],
"require": {
"php": "^7.4|^8.0"
"php": "^7.4|^8.0",
"ext-json": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^v3.0",
Expand Down
28 changes: 0 additions & 28 deletions src/Shiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,11 @@ public static function highlight(
]);
}

public function getAvailableLanguages(): array
{
$shikiResult = $this->callShiki('languages');

$languages = json_decode($shikiResult, true);

sort($languages);

return $languages;
}

public function __construct(string $defaultTheme = 'nord')
{
$this->defaultTheme = $defaultTheme;
}

public function getAvailableThemes(): array
{
$shikiResult = $this->callShiki('themes');

return json_decode($shikiResult, true);
}

public function languageIsAvailable(string $language): bool
{
return in_array($language, $this->getAvailableLanguages());
}

public function themeIsAvailable(string $theme): bool
{
return in_array($theme, $this->getAvailableThemes());
}

public function highlightCode(string $code, string $language, ?string $theme = null, ?array $options = []): string
{
$theme = $theme ?? $this->defaultTheme;
Expand Down
26 changes: 0 additions & 26 deletions tests/ShikiCustomRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,29 +129,3 @@

Shiki::highlight($code, 'invalid-language');
})->throws(Exception::class);

it('can get all available themes', function () {
$availableThemes = (new Shiki())->getAvailableThemes();

expect($availableThemes)->not()->toBeEmpty();
});

it('can get all available languages', function () {
$availableLanguages = (new Shiki())->getAvailableLanguages();

expect($availableLanguages)->not()->toBeEmpty();
});

it('can determine that a theme is available', function () {
$shiki = (new Shiki());

expect($shiki->themeIsAvailable('nord'))->toBeTrue();
expect($shiki->themeIsAvailable('non-existing-theme'))->toBeFalse();
});

it('can determine that a language is available', function () {
$shiki = (new Shiki());

expect($shiki->languageIsAvailable('php'))->toBeTrue();
expect($shiki->languageIsAvailable('non-existing-language'))->toBeFalse();
});
26 changes: 0 additions & 26 deletions tests/ShikiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,29 +126,3 @@

Shiki::highlight($code, 'invalid-language');
})->throws(Exception::class);

it('can get all available themes', function () {
$availableThemes = (new Shiki())->getAvailableThemes();

expect($availableThemes)->not()->toBeEmpty();
});

it('can get all available languages', function () {
$availableLanguages = (new Shiki())->getAvailableLanguages();

expect($availableLanguages)->not()->toBeEmpty();
});

it('can determine that a theme is available', function () {
$shiki = (new Shiki());

expect($shiki->themeIsAvailable('nord'))->toBeTrue();
expect($shiki->themeIsAvailable('non-existing-theme'))->toBeFalse();
});

it('can determine that a language is available', function () {
$shiki = (new Shiki());

expect($shiki->languageIsAvailable('php'))->toBeTrue();
expect($shiki->languageIsAvailable('non-existing-language'))->toBeFalse();
});

0 comments on commit cc1e021

Please sign in to comment.