Skip to content

@shikijs/cli ​

NPM versionNPM downloadsGitHub

Shiki in the command line.

Usage ​

The Shiki CLI works like cat command, but with syntax highlighting. It also supports remote files.

bash
npx @shikijs/cli README.md
bash
npx @shikijs/cli \
  'https://github.com/shikijs/shiki/blob/main/taze.config.ts?raw=true'

Install ​

You can also install it globally. Command aliases @shikijs/cli, shiki, skat are registered.

sh
npm i -g @shikijs/cli
sh
yarn global add @shikijs/cli
sh
pnpm add -g @shikijs/cli
sh
bun add -g @shikijs/cli
sh
deno install -gREn skat npm:@shikijs/cli
sh
skat src/index.ts

Options ​

--theme ​

Specify the theme to use. Defaults to vitesse-dark.

bash
npx @shikijs/cli README.md --theme=nord

--lang ​

Language is auto-inferred from the file extension. You can override it with --lang.

bash
npx @shikijs/cli src/index.js --lang=ts

--format ​

Specify the output format. Defaults to ansi. Supported values: ansi, html.

bash
npx @shikijs/cli README.md --format=html

Node.js API ​

The @shikijs/cli package also provides a Node.js API.

sh
npm i @shikijs/cli
sh
yarn add @shikijs/cli
sh
pnpm add @shikijs/cli
sh
bun add @shikijs/cli
sh
deno add npm:@shikijs/cli

codeToANSI ​

The 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.

ts
import { codeToANSI } from '@shikijs/cli'

const highlighted = await codeToANSI(source, 'typescript', 'nord')

console.log(highlighted)

codeToANSI takes three required parameters:

  1. code: string
  2. lang: BundledLanguage
  3. theme: BundledTheme

and one optional parameter:

  1. options?: CodeToANSIOptions

The color level of the emitted escape codes is explicit instead of being inferred from the environment, and defaults to 3 (truecolor). Use options.colorLevel to target a different level — pass the level reported by ansis to follow the current terminal, or 0 to get plain text:

ts
import { codeToANSI } from '@shikijs/cli'
import ansis from 'ansis'

const highlighted = await codeToANSI(source, 'typescript', 'nord', {
  colorLevel: ansis.level,
})

Released under the MIT License.