syntect()

フェンスドコードブロックに対して Rust ネイティブのシンタックスハイライトを有効にする syntect プラグインを生成します。Sublime Text のシンタックス定義を利用し、100 以上の言語に対応しています。

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

シグネチャ

function syntect(options?: SyntectPluginOptions): UnifastPlugin

パラメータ

options?

ハイライトエンジンの設定

プロパティデフォルト説明
engine"none" | "syntect""syntect"“syntect” は syntect ハイライタを使用し、“none” はハイライトを無効にします

使い方

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

使用例

シンタックスハイライトを有効にする

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>

ハイライトを無効にする

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