syntect()
Cria um plugin syntect que habilita syntax highlighting nativo em Rust para code blocks fenced. Usa definições de sintaxe do Sublime Text com suporte a mais de 100 linguagens.
import { syntect } from "@unifast/node";Assinatura
function syntect(options?: SyntectPluginOptions): UnifastPluginParâmetros
options?
Configuração da engine de highlighting
| Propriedade | Tipo | Padrão | Descrição |
|---|---|---|---|
engine | "none" | "syntect" | "syntect" | “syntect” usa o highlighter syntect; “none” desabilita o highlighting |
Uso
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 classesExemplos
Habilitar 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>Desabilitar 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