fix(website): code block with an unknown language

This commit is contained in:
LukaDev 2024-10-14 16:10:47 +02:00
parent 4c268e1f05
commit bc9df65c89
3 changed files with 29 additions and 0 deletions

Binary file not shown.

View file

@ -53,5 +53,8 @@
"shiki": "^1.22.0",
"tar-stream": "^3.1.7",
"unified": "^11.0.5"
},
"patchedDependencies": {
"@shikijs/rehype@1.22.0": "patches/@shikijs%2Frehype@1.22.0.patch"
}
}

View file

@ -0,0 +1,26 @@
@shikis/rehype doesn't use the `fallbackLanguage` if `lazy` is used.
--- a/dist/core.mjs
+++ b/dist/core.mjs
@@ -1,6 +1,8 @@
import { visit } from 'unist-util-visit';
import { toString } from 'hast-util-to-string';
+import { bundledLanguages } from 'shiki';
+
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)
return defaultLanguage;
+
+ if (!(lang in bundledLanguages))
+ return fallbackLanguage;
+
if (highlighter.getLoadedLanguages().includes(lang))
return lang;
if (lazy) {