createShikiPlugin()

एक Shiki-powered syntax highlighting plugin बनाएँ। एक async function जो Shiki highlighter को initialize करता है और एक HAST transform के साथ UnifastPlugin return करता है।

import { createShikiPlugin } from "@unifast/shiki";

Signature

async function createShikiPlugin(
  options?: ShikiTransformerOptions,
): Promise<UnifastPlugin>

Parameters

options?

Shiki configuration (themes, languages)

PropertyTypeDefaultविवरण
themesBundledTheme[]["github-dark"]load करने के लिए Shiki themes
defaultThemeBundledThemethemes में पहला themerendering के लिए Default theme
langsBundledLanguage[][]load करने के लिए भाषाएँ। केवल loaded भाषाएँ ही highlight होंगी।

उपयोग

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);
// Code blocks Shiki-generated <span> elements के साथ highlight होते हैं

उदाहरण

एकल theme

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-highlighted <span> elements वाला <pre>

कई themes

import { createShikiPlugin } from "@unifast/shiki";

const shiki = await createShikiPlugin({
  themes: ["github-dark", "github-light", "dracula"],
  defaultTheme: "github-dark",
  langs: ["typescript", "rust", "python"],
});

// compile() के साथ उपयोग करें — defaultTheme code blocks पर लागू होता है

अन्य plugins के साथ

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