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)

ÖzellikTürVarsayılanAçıklama
themesBundledTheme[]["github-dark"]Yüklenecek Shiki temaları
defaultThemeBundledThemethemes’deki ilk temaRender için varsayılan tema
langsBundledLanguage[][]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ır

Diğ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],
});