fix(website): shiki fallback language patch (#5)

This commit is contained in:
Luka 2024-10-30 18:20:24 +01:00 committed by GitHub
parent 236edff6a0
commit 1640dab0c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 75 additions and 79 deletions

Binary file not shown.

View file

@ -65,7 +65,7 @@
"vfile": "^6.0.3" "vfile": "^6.0.3"
}, },
"patchedDependencies": { "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" "packageManager": "bun@1.1.33"
} }

View file

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