https://github.com/xavierlacot/shiki-cli-binary
💅 Build the shiki syntax highlighter, with all the languages included, as a command line binary using Bun
https://github.com/xavierlacot/shiki-cli-binary
bun shiki syntax-highlighting
Last synced: about 2 months ago
JSON representation
💅 Build the shiki syntax highlighter, with all the languages included, as a command line binary using Bun
- Host: GitHub
- URL: https://github.com/xavierlacot/shiki-cli-binary
- Owner: xavierlacot
- License: mit
- Created: 2025-01-29T10:17:05.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-30T13:49:12.000Z (over 1 year ago)
- Last Synced: 2026-03-10T14:29:00.230Z (3 months ago)
- Topics: bun, shiki, syntax-highlighting
- Language: JavaScript
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Shiki-cli-binary
This repository allows to build the [shiki](https://shiki.style/) syntax highlighter, with all the languages and themes included, as a command line binary using [Bun](https://bun.sh).
## Why?
The shiki syntax highlighter is a great tool to highlight code in a web page. However, it is written in TypeScript and requires a Node.js environment to run. This repository allows to build a binary that can be run on any platform without any dependency, making deployment easier.
## Deploy
You can download the binary:
```bash
wget https://github.com/xavierlacot/shiki-cli-binary/releases/download/v0.0.1/shiki-cli
chmod +x shiki-cli
```
## Usage
### Highlight a code string
The following command outputs an highlighted code string to the standard output:
```bash
./shiki-cli /path/to/source-code.xyz --lang=language --theme=theme
```
The `--lang` and `--theme` options are optional. If not provided, the default language is `text` and the default theme is `monokai`.
### JSON mode
The `--json` option allows to process multiple code snippets at once, which can be useful to improve performance.
When the `--json` option is provided, the input is expected to be a JSON array in the following format:
```
[
{
"input": "source code",
"lang": "language",
"theme": "theme",
...
},
...
]
```
The `lang` and `theme` fields are optional. If not provided, it defaults to the `--lang` and `--theme` cli options, or to `text` and `monokai` if not provided.
Each object in the array is processed and the output is a JSON array with the same structure, with the `output` field containing the highlighted code. If the input array contained extra fields, they are preserved in the output. For example:
```json
// input.json
[
{
"lang": "typescript",
"input": "function greet(): void {\n console.log('Hello, world!');\n}\ngreet();",
"reference": "550e8400-e29b-41d4-a716-446655440004"
},
{
"lang": "php",
"input": "",
"reference": "550e8400-e29b-41d4-a716-446655440005"
}
]
```
```bash
./shiki-cli input.json --json > output.json
```
```json
// output.json
[
{
"lang": "typescript",
"input": "function greet(): void {\n console.log('Hello, world!');\n}\ngreet();",
"reference": "550e8400-e29b-41d4-a716-446655440004",
"output": "
function greet(): void {\n console.log('Hello, world!');\n}\ngreet();
"
},
{
"lang": "php",
"input": "",
"reference": "550e8400-e29b-41d4-a716-446655440005",
"output": "<?php\nfunction greet() {\n echo 'Hello, world!';\n}\ngreet();\n?>
"
}
]
```
## Development
### Install
This project requires the bun package manager ([see install instructions](https://bun.sh/docs/installation)).
```bash
git clone https://github.com/xavierlacot/shiki-cli-binary.git
cd shiki-cli-binary
bun install
```
### Build
```bash
bun binary
```
This generates a binary named `shiki-cli` in the current directory.
### Lint
Several commands are available to check, lint and format the code. The rely on [Biome](https://biomejs.dev/):
```bash
bun check
bun format
bun lint
```