docs/packages/cli.md
Shiki in the command line.
The Shiki CLI works like cat command, but with syntax highlighting.
It also supports remote files.
npx @shikijs/cli README.md
npx @shikijs/cli \
'https://github.com/shikijs/shiki/blob/main/taze.config.ts?raw=true'
You can also install it globally. Command aliases @shikijs/cli, shiki, skat are registered.
::: code-group
npm i -g @shikijs/cli
yarn global add @shikijs/cli
pnpm add -g @shikijs/cli
bun add -g @shikijs/cli
deno install -gREn skat npm:@shikijs/cli
:::
skat src/index.ts
--themeSpecify the theme to use. Defaults to vitesse-dark.
npx @shikijs/cli README.md --theme=nord
--langLanguage is auto-inferred from the file extension. You can override it with --lang.
npx @shikijs/cli src/index.js --lang=ts
--formatSpecify the output format. Defaults to ansi.
Supported values: ansi, html.
npx @shikijs/cli README.md --format=html
The @shikijs/cli package also provides a Node.js API.
::: code-group
npm i @shikijs/cli
yarn add @shikijs/cli
pnpm add @shikijs/cli
bun add @shikijs/cli
deno add npm:@shikijs/cli
:::
codeToANSIThe asynchronous codeToANSI function allows you to convert code to ANSI escape codes for terminal output.
This is useful for rendering syntax-highlighted code in the terminal.
import { codeToANSI } from '@shikijs/cli'
const highlighted = await codeToANSI(source, 'typescript', 'nord')
console.log(highlighted)
codeToANSI takes three required parameters:
code: stringlang: BundledLanguagetheme: BundledTheme