diff --git a/bin/shiki.js b/bin/shiki.js index e649beb..38461fb 100644 --- a/bin/shiki.js +++ b/bin/shiki.js @@ -38,7 +38,22 @@ async function main(args) { if (!customLanguages[language]) await highlighter.loadLanguage(language); if (args[0] === 'languages') { - process.stdout.write(JSON.stringify(highlighter.getLoadedLanguages())); + process.stdout.write( + JSON.stringify([ + ...Object.keys(shiki.bundledLanguagesBase), + ...Object.keys(customLanguages), + ]) + ); + return; + } + + if (args[0] === 'aliases') { + process.stdout.write( + JSON.stringify([ + ...Object.keys(shiki.bundledLanguages), + ...Object.keys(customLanguages), + ]) + ); return; } diff --git a/src/Shiki.php b/src/Shiki.php index 372ff76..955bbb7 100644 --- a/src/Shiki.php +++ b/src/Shiki.php @@ -62,7 +62,11 @@ public function getAvailableThemes(): array public function languageIsAvailable(string $language): bool { - return in_array($language, $this->getAvailableLanguages()); + $shikiResult = $this->callShiki('aliases'); + + $aliases = json_decode($shikiResult, true); + + return in_array($language, $aliases); } public function themeIsAvailable(string $theme): bool diff --git a/tests/ShikiCustomRenderTest.php b/tests/ShikiCustomRenderTest.php index 3acb807..0a950f3 100644 --- a/tests/ShikiCustomRenderTest.php +++ b/tests/ShikiCustomRenderTest.php @@ -140,6 +140,9 @@ $availableLanguages = (new Shiki())->getAvailableLanguages(); expect($availableLanguages)->not()->toBeEmpty(); + expect($availableLanguages)->toContain('javascript'); + // should not include aliases + expect($availableLanguages)->not()->toContain('js'); }); it('can determine that a theme is available', function () { @@ -154,4 +157,7 @@ expect($shiki->languageIsAvailable('php'))->toBeTrue(); expect($shiki->languageIsAvailable('non-existing-language'))->toBeFalse(); + expect($shiki->languageIsAvailable('javascript'))->toBeTrue(); + // should match aliases + expect($shiki->languageIsAvailable('js'))->toBeTrue(); }); diff --git a/tests/ShikiTest.php b/tests/ShikiTest.php index f961ed6..6599740 100644 --- a/tests/ShikiTest.php +++ b/tests/ShikiTest.php @@ -137,6 +137,9 @@ $availableLanguages = (new Shiki())->getAvailableLanguages(); expect($availableLanguages)->not()->toBeEmpty(); + expect($availableLanguages)->toContain('javascript'); + // should not include aliases + expect($availableLanguages)->not()->toContain('js'); }); it('can determine that a theme is available', function () { @@ -151,4 +154,7 @@ expect($shiki->languageIsAvailable('php'))->toBeTrue(); expect($shiki->languageIsAvailable('non-existing-language'))->toBeFalse(); + expect($shiki->languageIsAvailable('javascript'))->toBeTrue(); + // should match aliases + expect($shiki->languageIsAvailable('js'))->toBeTrue(); }); diff --git a/tests/testfiles/alt-bin/shiki.js b/tests/testfiles/alt-bin/shiki.js index c2ff3c1..acd09a1 100644 --- a/tests/testfiles/alt-bin/shiki.js +++ b/tests/testfiles/alt-bin/shiki.js @@ -38,7 +38,22 @@ async function main(args) { if (!customLanguages[language]) await highlighter.loadLanguage(language); if (args[0] === 'languages') { - process.stdout.write(JSON.stringify(highlighter.getLoadedLanguages())); + process.stdout.write( + JSON.stringify([ + ...Object.keys(shiki.bundledLanguagesBase), + ...Object.keys(customLanguages), + ]) + ); + return; + } + + if (args[0] === 'aliases') { + process.stdout.write( + JSON.stringify([ + ...Object.keys(shiki.bundledLanguages), + ...Object.keys(customLanguages), + ]) + ); return; }