fix(website): use custom highlighter

This commit is contained in:
LukaDev 2024-10-12 23:35:34 +02:00
parent fc0e9f96cd
commit 6c20193bd6

View file

@ -1,5 +1,5 @@
import { fetchRegistry, RegistryHttpError } from "$lib/registry-api" import { fetchRegistry, RegistryHttpError } from "$lib/registry-api"
import rehypeShiki from "@shikijs/rehype" import rehypeShikiFromHighlighter from "@shikijs/rehype/core"
import rehypeRaw from "rehype-raw" import rehypeRaw from "rehype-raw"
import rehypeSanitize from "rehype-sanitize" import rehypeSanitize from "rehype-sanitize"
import rehypeStringify from "rehype-stringify" import rehypeStringify from "rehype-stringify"
@ -7,10 +7,15 @@ import remarkGemoji from "remark-gemoji"
import remarkGfm from "remark-gfm" import remarkGfm from "remark-gfm"
import remarkParse from "remark-parse" import remarkParse from "remark-parse"
import remarkRehype from "remark-rehype" import remarkRehype from "remark-rehype"
import { createCssVariablesTheme } from "shiki" import { createCssVariablesTheme, createHighlighter } from "shiki"
import { unified } from "unified" import { unified } from "unified"
import type { PageLoad } from "./$types" import type { PageLoad } from "./$types"
const highlighter = await createHighlighter({
themes: [],
langs: [],
})
const fetchReadme = async ( const fetchReadme = async (
fetcher: typeof fetch, fetcher: typeof fetch,
name: string, name: string,
@ -50,14 +55,14 @@ export const load: PageLoad = async ({ parent, fetch }) => {
.use(remarkRehype, { allowDangerousHtml: true }) .use(remarkRehype, { allowDangerousHtml: true })
.use(rehypeRaw) .use(rehypeRaw)
.use(rehypeSanitize) .use(rehypeSanitize)
.use(rehypeShiki, { .use(rehypeShikiFromHighlighter, highlighter, {
lazy: true,
theme: createCssVariablesTheme({ theme: createCssVariablesTheme({
name: "css-variables", name: "css-variables",
variablePrefix: "--shiki-", variablePrefix: "--shiki-",
variableDefaults: {}, variableDefaults: {},
fontStyle: true, fontStyle: true,
}), }),
lazy: true,
fallbackLanguage: "text", fallbackLanguage: "text",
}) })
.use(rehypeStringify) .use(rehypeStringify)