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

@ -1,71 +1,71 @@
{ {
"name": "website", "name": "website",
"version": "0.0.1", "version": "0.0.1",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite dev", "dev": "vite dev",
"build": "vite build", "build": "vite build",
"preview": "vite preview", "preview": "vite preview",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "prettier --check . && eslint .", "lint": "prettier --check . && eslint .",
"format": "prettier --write ." "format": "prettier --write ."
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/adapter-vercel": "^5.4.6", "@sveltejs/adapter-vercel": "^5.4.6",
"@sveltejs/kit": "^2.7.3", "@sveltejs/kit": "^2.7.3",
"@sveltejs/vite-plugin-svelte": "^4.0.0", "@sveltejs/vite-plugin-svelte": "^4.0.0",
"@tailwindcss/typography": "^0.5.15", "@tailwindcss/typography": "^0.5.15",
"@types/eslint": "^9.6.1", "@types/eslint": "^9.6.1",
"@types/gunzip-maybe": "^1.4.2", "@types/gunzip-maybe": "^1.4.2",
"@types/tar-stream": "^3.1.3", "@types/tar-stream": "^3.1.3",
"autoprefixer": "^10.4.20", "autoprefixer": "^10.4.20",
"eslint": "^9.13.0", "eslint": "^9.13.0",
"eslint-config-prettier": "^9.1.0", "eslint-config-prettier": "^9.1.0",
"eslint-plugin-svelte": "^2.46.0", "eslint-plugin-svelte": "^2.46.0",
"globals": "^15.11.0", "globals": "^15.11.0",
"mdsvex": "^0.12.3", "mdsvex": "^0.12.3",
"prettier": "^3.3.3", "prettier": "^3.3.3",
"prettier-plugin-svelte": "^3.2.7", "prettier-plugin-svelte": "^3.2.7",
"prettier-plugin-tailwindcss": "^0.6.8", "prettier-plugin-tailwindcss": "^0.6.8",
"svelte": "^5.1.4", "svelte": "^5.1.4",
"svelte-check": "^4.0.5", "svelte-check": "^4.0.5",
"tailwindcss": "^3.4.14", "tailwindcss": "^3.4.14",
"typescript": "^5.6.3", "typescript": "^5.6.3",
"typescript-eslint": "^8.12.2", "typescript-eslint": "^8.12.2",
"vite": "^5.4.10" "vite": "^5.4.10"
}, },
"type": "module", "type": "module",
"dependencies": { "dependencies": {
"@fontsource-variable/nunito-sans": "^5.1.0", "@fontsource-variable/nunito-sans": "^5.1.0",
"@shikijs/rehype": "^1.22.2", "@shikijs/rehype": "^1.22.2",
"@types/hast": "^3.0.4", "@types/hast": "^3.0.4",
"@types/unist": "^3.0.3", "@types/unist": "^3.0.3",
"bits-ui": "next", "bits-ui": "next",
"date-fns": "^4.1.0", "date-fns": "^4.1.0",
"gunzip-maybe": "^1.4.2", "gunzip-maybe": "^1.4.2",
"hast-util-heading": "^3.0.0", "hast-util-heading": "^3.0.0",
"hast-util-heading-rank": "^3.0.0", "hast-util-heading-rank": "^3.0.0",
"hast-util-to-text": "^4.0.2", "hast-util-to-text": "^4.0.2",
"lucide-svelte": "^0.446.0", "lucide-svelte": "^0.446.0",
"rehype-infer-description-meta": "^2.0.0", "rehype-infer-description-meta": "^2.0.0",
"rehype-raw": "^7.0.0", "rehype-raw": "^7.0.0",
"rehype-sanitize": "^6.0.0", "rehype-sanitize": "^6.0.0",
"rehype-slug": "^6.0.0", "rehype-slug": "^6.0.0",
"rehype-stringify": "^10.0.1", "rehype-stringify": "^10.0.1",
"remark-frontmatter": "^5.0.0", "remark-frontmatter": "^5.0.0",
"remark-gemoji": "^8.0.0", "remark-gemoji": "^8.0.0",
"remark-gfm": "^4.0.0", "remark-gfm": "^4.0.0",
"remark-parse": "^11.0.0", "remark-parse": "^11.0.0",
"remark-rehype": "^11.1.1", "remark-rehype": "^11.1.1",
"shiki": "^1.22.2", "shiki": "^1.22.2",
"tar-stream": "^3.1.7", "tar-stream": "^3.1.7",
"unified": "^11.0.5", "unified": "^11.0.5",
"unist-util-map": "^4.0.0", "unist-util-map": "^4.0.0",
"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;