syntect()
Создаёт плагин syntect, включающий нативную подсветку синтаксиса на Rust для огороженных блоков кода. На основе определений синтаксиса 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);
// Блоки кода подсвечены элементами <span> и CSS-классамиПримеры
Включение подсветки синтаксиса
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);
// Блоки кода отрисовываются без подсветки синтаксиса