From cc1e02103e9a4166800653d31bfa977a229808ca Mon Sep 17 00:00:00 2001 From: Rias Date: Mon, 19 Feb 2024 10:00:18 +0100 Subject: [PATCH] Remove methods --- bin/shiki.js | 11 +---------- composer.json | 3 ++- src/Shiki.php | 28 ---------------------------- tests/ShikiCustomRenderTest.php | 26 -------------------------- tests/ShikiTest.php | 26 -------------------------- 5 files changed, 3 insertions(+), 91 deletions(-) diff --git a/bin/shiki.js b/bin/shiki.js index 8f382ed..5e00269 100644 --- a/bin/shiki.js +++ b/bin/shiki.js @@ -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], { @@ -76,6 +66,7 @@ function loadLanguage(language) { return JSON.parse(content); } + function getLanguagePath(language) { const url = path.join(__dirname, '..', 'languages', `${language}.tmLanguage.json`); diff --git a/composer.json b/composer.json index 1914928..d3f2ca0 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Shiki.php b/src/Shiki.php index 372ff76..3d0f67c 100644 --- a/src/Shiki.php +++ b/src/Shiki.php @@ -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; diff --git a/tests/ShikiCustomRenderTest.php b/tests/ShikiCustomRenderTest.php index 3acb807..fdf8882 100644 --- a/tests/ShikiCustomRenderTest.php +++ b/tests/ShikiCustomRenderTest.php @@ -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(); -}); diff --git a/tests/ShikiTest.php b/tests/ShikiTest.php index f961ed6..7cf74fb 100644 --- a/tests/ShikiTest.php +++ b/tests/ShikiTest.php @@ -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(); -});