fix(website): shiki fallback language patch

This commit is contained in:
LukaDev 2024-10-30 18:10:27 +01:00
parent 236edff6a0
commit 7468d4e457
3 changed files with 75 additions and 79 deletions

Binary file not shown.

View file

@ -65,7 +65,7 @@
"vfile": "^6.0.3"
},
"patchedDependencies": {
"@shikijs/rehype@1.22.0": "patches/@shikijs%2Frehype@1.22.0.patch"
"@shikijs/rehype@1.22.2": "patches/@shikijs%2Frehype@1.22.2.patch"
},
"packageManager": "bun@1.1.33"
}

View file

@ -2,7 +2,7 @@
--- a/dist/core.mjs
+++ b/dist/core.mjs
@@ -1,6 +1,8 @@
@@ -2,6 +2,8 @@ import { isSpecialLang } from 'shiki/core';
import { visit } from 'unist-util-visit';
import { toString } from 'hast-util-to-string';
@ -11,16 +11,12 @@
const InlineCodeHandlers = {
"tailing-curly-colon": (_tree, node) => {
const raw = toString(node);
@@ -90,8 +92,12 @@ function rehypeShikiFromHighlighter(highlighter, options) {
const languageQueue = [];
const queue = [];
function getLanguage(lang) {
if (!lang)
@@ -95,6 +97,8 @@ function rehypeShikiFromHighlighter(highlighter, options) {
return defaultLanguage;
+
if (highlighter.getLoadedLanguages().includes(lang) || isSpecialLang(lang))
return lang;
+ if (!(lang in bundledLanguages))
+ return fallbackLanguage;
+
if (highlighter.getLoadedLanguages().includes(lang))
return lang;
if (lazy) {
languageQueue.push(lang);
return lang;