syntect()
Crea un plugin syntect que habilita el resaltado de sintaxis nativo en Rust para bloques de código fenced. Impulsado por las definiciones de sintaxis de Sublime Text, con soporte para más de 100 lenguajes.
import { syntect } from "@unifast/node";Firma
function syntect(options?: SyntectPluginOptions): UnifastPluginParámetros
options?
Configuración del motor de resaltado
| Propiedad | Tipo | Por defecto | Descripción |
|---|---|---|---|
engine | "none" | "syntect" | "syntect" | “syntect” usa el highlighter de syntect; “none” desactiva el resaltado |
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 classesEjemplos
Habilitar el resaltado de sintaxis
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>Desactivar el resaltado
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