highlight()
Membuat plugin syntax highlighting highlight.js yang melakukan highlight pada code block fenced melalui transform HAST menggunakan lowlight.
import { highlight } from "@unifast/highlight";Signature
function highlight(): UnifastPluginParameter
Tidak ada.
Penggunaan
import { compile } from "@unifast/node";
import { highlight } from "@unifast/highlight";
const md = `
\`\`\`typescript
const greeting: string = "Hello";
console.log(greeting);
\`\`\`
`;
const result = compile(md, {
plugins: [highlight()],
});
console.log(result.output);
// <pre><code class="language-typescript hljs">
// <span class="hljs-keyword">const</span> ...
// </code></pre>Contoh
Dengan banyak bahasa
import { compile } from "@unifast/node";
import { highlight } from "@unifast/highlight";
const md = `
\`\`\`python
def hello():
print("Hello, world!")
\`\`\`
\`\`\`css
.container {
display: flex;
}
\`\`\`
`;
const result = compile(md, { plugins: [highlight()] });
// Both code blocks are highlighted with appropriate highlight.js classesDengan plugin lain
import { compile, gfm, frontmatter } from "@unifast/node";
import { highlight } from "@unifast/highlight";
const result = compile(source, {
plugins: [gfm(), frontmatter(), highlight()],
});