syntect()

Membuat plugin syntect yang mengaktifkan syntax highlighting Rust-native untuk fenced code block. Ditenagai oleh definisi sintaks Sublime Text dengan dukungan untuk 100+ bahasa.

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

Signature

function syntect(options?: SyntectPluginOptions): UnifastPlugin

Parameter

options?

Konfigurasi engine highlighting

PropertiTipeDefaultDeskripsi
engine"none" | "syntect""syntect"“syntect” menggunakan highlighter syntect; “none” menonaktifkan highlighting

Penggunaan

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

const md = `
# Code Example

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

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

console.log(result.output);
// Code blocks are syntax highlighted with <span> elements and CSS classes

Contoh

Mengaktifkan syntax highlighting

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

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

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

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

Menonaktifkan highlighting

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

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

console.log(result.output);
// Code blocks are rendered without syntax highlighting