shiki
Shiki 3+ syntax highlighting. Use when highlighting code blocks, MDX content, or building code editors.
Installation
Follow the repository instructions for this skill and your agent. Review the files and dependencies before adding it to your workflow.
View source ↗GuidesSkill instructions
Shiki 3+
Create highlighter — v3 pattern
import { createHighlighter } from 'shiki'
const highlighter = await createHighlighter({
themes: ['nord', 'github-dark'],
langs: ['typescript', 'python'],
})
const html = highlighter.codeToHtml('const x = 1', {
lang: 'typescript',
theme: 'nord',
})
// NOT getHighlighter — that's v1
Shorthand functions — no highlighter needed
import { codeToHtml, codeToTokens, codeToHast } from 'shiki'
// Direct usage (creates internal highlighter)
const html = await codeToHtml('const x = 1', {
lang: 'typescript',
theme: 'github-dark',
})
const { tokens } = await codeToTokens(code, { lang: 'ts', theme: 'nord' })
const hast = await codeToHast(code, { lang: 'css', theme: 'min-dark' })
Rehype integration — @shikijs/rehype
import rehypeShiki from '@shikijs/rehype'
import remarkRehype from 'remark-rehype'
import { unified } from 'unified'
const processor = unified()
.use(remarkParse)
.use(remarkRehype)
.use(rehypeShiki, {
themes: {
light: 'github-light',
dark: 'github-dark',
},
// Inline code: `code{:lang}`
inline: 'tailing-curly-colon',
})
Transformers — hook into rendering
import { transformerNotationHighlight } from '@shikijs/transformers'
const html = await codeToHtml(code, {
lang: 'ts',
theme: 'nord',
transformers: [
transformerNotationHighlight(), // [!code highlight]
{
// Custom transformer
line(node, line) {
node.properties['data-line'] = line
},
code(node) {
this.addClassToHast(node, 'my-code-block')
},
},
],
})
Fine-grained bundles — v3 engine system
import { createHighlighterCore } from 'shiki/core'
import { createOnigurumaEngine } from 'shiki/engine/oniguruma'
const highlighter = await createHighlighterCore({
themes: [import('@shikijs/themes/nord')],
langs: [import('@shikijs/langs/typescript')],
engine: createOnigurumaEngine(() => import('shiki/wasm')),
})
// NOT loadWasm from 'shiki' — that's v1/v2
Avoid
-
getHighlighter()→createHighlighter() -
loadWasmfrom'shiki'→createOnigurumaEnginefrom'shiki/engine/oniguruma' -
@shikijs/compat→ discontinued, use main package -
postprocesshook in rehype → doesn't run, useroothook instead -
createdBundledHighlighter(fn, fn)→ single object argument in v3
Examples
Read the usage examples in the source repository.
View source ↗Source history
- Indexed on
- 2026-01-20
- Index updated
- 2026-03-03
- Branch
- main
Index and sync dates describe this directory. View the source repository for code history.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!