createShikiPlugin()
Shiki destekli bir sözdizimi vurgulama plugin'i oluşturur. Shiki vurgulayıcısını başlatan ve HAST dönüşümüne sahip bir UnifastPlugin döndüren asenkron bir fonksiyondur.
import { createShikiPlugin } from "@unifast/shiki";İmza
async function createShikiPlugin(
options?: ShikiTransformerOptions,
): Promise<UnifastPlugin>Parametreler
options?
Shiki yapılandırması (temalar, diller)
| Özellik | Tür | Varsayılan | Açıklama |
|---|---|---|---|
themes | BundledTheme[] | ["github-dark"] | Yüklenecek Shiki temaları |
defaultTheme | BundledTheme | themes’deki ilk tema | Render için varsayılan tema |
langs | BundledLanguage[] | [] | Yüklenecek diller. Yalnızca yüklenen diller vurgulanır. |
Kullanım
import { compile } from "@unifast/node";
import { createShikiPlugin } from "@unifast/shiki";
const shiki = await createShikiPlugin({
themes: ["github-dark", "github-light"],
defaultTheme: "github-dark",
langs: ["typescript", "rust", "json", "html", "css"],
});
const result = compile(md, {
plugins: [shiki],
});
console.log(result.output);
// Kod blokları Shiki tarafından üretilen <span> elemanlarıyla vurgulanırÖrnekler
Tek tema
import { compile } from "@unifast/node";
import { createShikiPlugin } from "@unifast/shiki";
const shiki = await createShikiPlugin({
themes: ["github-dark"],
langs: ["typescript"],
});
const result = compile("```ts\nconst x = 1;\n```", {
plugins: [shiki],
});
console.log(result.output);
// Shiki ile vurgulanmış <span> elemanları içeren <pre>Birden fazla tema
import { createShikiPlugin } from "@unifast/shiki";
const shiki = await createShikiPlugin({
themes: ["github-dark", "github-light", "dracula"],
defaultTheme: "github-dark",
langs: ["typescript", "rust", "python"],
});
// compile() ile kullanın — defaultTheme kod bloklarına uygulanırDiğer plugin’ler ile
import { compile, gfm, frontmatter } from "@unifast/node";
import { createShikiPlugin } from "@unifast/shiki";
const shiki = await createShikiPlugin({
themes: ["github-dark"],
langs: ["typescript"],
});
const result = compile(md, {
plugins: [gfm(), frontmatter(), shiki],
});