# cli-highlight

> Syntax highlighting in your terminal

Latest version **2.1.11** (published 2021-03-28) · ISC license · 0 weekly downloads

## Install

```sh
npm install cli-highlight
pnpm add cli-highlight
yarn add cli-highlight
bun add cli-highlight
```

Provides the command `highlight`.

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 2.1.11 |
| Published | 2021-03-28 |
| First published | 2016-08-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 6 |
| Unpacked size | 41.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 336 |
| Author | Felix Becker |
| Maintainers | felixfbecker |
| Keywords | terminal, syntax, highlight, color, cli, ansi |

## Links

- npm: https://www.npmjs.com/package/cli-highlight
- Repository: https://github.com/felixfbecker/cli-highlight
- Homepage: https://github.com/felixfbecker/cli-highlight#readme
- Issues: https://github.com/felixfbecker/cli-highlight/issues
- npm.io page: https://npm.io/package/cli-highlight

## Dependencies (6)

- [mz](https://npm.io/package/mz.md) ^2.4.0
- [chalk](https://npm.io/package/chalk.md) ^4.0.0
- [yargs](https://npm.io/package/yargs.md) ^16.0.0
- [parse5](https://npm.io/package/parse5.md) ^5.1.1
- [highlight.js](https://npm.io/package/highlight.js.md) ^10.7.1
- [parse5-htmlparser2-tree-adapter](https://npm.io/package/parse5-htmlparser2-tree-adapter.md) ^6.0.0

## Alternatives

- [@oh-my-pi/pi-natives](https://npm.io/package/@oh-my-pi/pi-natives.md) — 51.8K weekly downloads
- [@capgo/capacitor-light-sensor](https://npm.io/package/@capgo/capacitor-light-sensor.md) — 3.0K weekly downloads
- [@heyhuynhgiabuu/pi-diff](https://npm.io/package/@heyhuynhgiabuu/pi-diff.md) — 492 weekly downloads
- [@lotsa/verdant-lang-asm](https://npm.io/package/@lotsa/verdant-lang-asm.md) — 38 weekly downloads
- [new-era-syntax](https://npm.io/package/new-era-syntax.md) — 20 weekly downloads

## Recent versions

- 2.1.11 (latest) — 2021-03-28
- 2.1.10 — 2021-01-08
- 2.1.9 — 2020-12-01
- 2.1.8 — 2020-11-21
- 2.1.7 — 2020-11-21
- 2.1.6 — 2020-11-21
- 2.1.5 — 2020-11-21
- 2.1.4 — 2019-11-16
- 2.1.3 — 2019-11-09
- 2.1.2 — 2019-11-09
- 2.1.1 — 2019-05-04
- 2.1.0 — 2019-03-22
- 2.0.0 — 2018-05-01
- 1.2.3 — 2017-11-30
- 1.2.2 — 2017-11-27
- … 9 more at https://npm.io/package/cli-highlight/versions

## README

# cli-highlight

> Syntax highlighting in your terminal

[![npm](https://img.shields.io/npm/v/cli-highlight.svg)](https://www.npmjs.com/package/cli-highlight)
[![downloads](https://img.shields.io/npm/dm/cli-highlight.svg)](https://www.npmjs.com/package/cli-highlight)
[![CI status](https://github.com/felixfbecker/cli-highlight/workflows/build/badge.svg?branch=main)](https://github.com/felixfbecker/cli-highlight/actions)
[![codecov](https://codecov.io/gh/felixfbecker/cli-highlight/branch/main/graph/badge.svg)](https://codecov.io/gh/felixfbecker/cli-highlight)
![node](http://img.shields.io/node/v/cli-highlight.svg)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
[![license](https://img.shields.io/npm/l/cli-highlight.svg)](https://github.com/felixfbecker/cli-highlight/blob/main/LICENSE.txt)

## Example

![Example Output](media/screenshot.svg)

## CLI Usage
Output a file
```sh
$ highlight package.json
```

Color output of another program with piping. Example: A database migration script that logs SQL Queries
```sh
$ db-migrate --dry-run | highlight
```

Command line options:
```html
Usage: highlight [options] [file]

Outputs a file or STDIN input with syntax highlighting

Options:
  --language, -l  Set the langugage explicitely
                  If omitted will try to auto-detect
  --theme, -t     Use a theme defined in a JSON file
  --version, -v   Show version number                                   [boolean]
  --help, -h      Show help                                             [boolean]
```

## Programmatic Usage

You can use this module programmatically to highlight logs of your Node app. Example:

```js
const highlight = require('cli-highlight').highlight
const Sequelize = require('sequelize')

const db = new Sequelize(process.env.DB, {
  logging(log) {
    console.log(highlight(log, {language: 'sql', ignoreIllegals: true}))
  }
})
```

Detailed API documenation can be found [here](http://cli-highlight.surge.sh/).

## Themes
You can write your own theme in a JSON file and pass it with `--theme`.
The key must be one of the [highlight.js CSS class names](http://highlightjs.readthedocs.io/en/latest/css-classes-reference.html) or `"default"`,
and the value must be one or an array of [Chalk styles](https://github.com/chalk/chalk#styles) to be applied to that token.

```json
{
  "keyword": "blue",
  "built_in": ["cyan", "dim"],
  "string": "red",
  "default": "gray"
}
```

The style for `"default"` will be applied to any substrings not handled by highlight.js. The specifics depend on the language but this typically includes things like commas in parameter lists, semicolons at the end of lines, etc.

The theme is combined with the [default theme](http://cli-highlight.surge.sh/globals.html#default_theme).
The default theme is still not colored a lot or optimized for many languages, PRs welcome!

## Supported Languages
[All languages of highlight.js](https://highlightjs.org/static/demo/) are supported.
Check a [CI build](https://travis-ci.org/felixfbecker/cli-highlight) for examples of all the different languages and their highlighting.

## Contributing
The module is written in TypeScript and can be compiled with `npm run build`.
`npm run watch` starts `tsc` in watch mode. Tests are written with mocha.

Improving language support is done by adding more colors to the tokens in the default theme and writing more tests.

---
_Source: https://npm.io/package/cli-highlight · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
