treeSitter()

एक Tree-sitter plugin बनाएँ जो Tree-sitter parsing library का उपयोग करके fenced code blocks के लिए syntax highlighting enable करता है।

import { treeSitter } from "@unifast/node";

Signature

function treeSitter(options?: TreeSitterPluginOptions): UnifastPlugin

Parameters

options?

Highlighting engine configuration

PropertyTypeDefaultविवरण
engine"none" | "treeSitter""treeSitter"“treeSitter” Tree-sitter highlighter का उपयोग करता है; “none” highlighting disable करता है

उपयोग

import { compile, treeSitter } from "@unifast/node";

const md = `
# Code Example

\`\`\`rust
fn main() {
    println!("Hello, world!");
}
\`\`\`
`;

const result = compile(md, {
  plugins: [
    treeSitter({
      engine: "treeSitter",
    }),
  ],
});

console.log(result.output);
// Code blocks <span> elements और CSS classes के साथ syntax highlighted होते हैं

उदाहरण

Syntax highlighting enable करें

import { compile, treeSitter } from "@unifast/node";

const md = `
\`\`\`typescript
const greeting: string = "Hello";
console.log(greeting);
\`\`\`
`;

const result = compile(md, { plugins: [treeSitter()] });

console.log(result.output);
// <pre><code class="language-typescript">
//   <span class="...">const</span> ...
// </code></pre>

Highlighting disable करें

import { compile, treeSitter } from "@unifast/node";

const result = compile(md, {
  plugins: [treeSitter({ engine: "none" })],
});

console.log(result.output);
// Code blocks syntax highlighting के बिना render होते हैं