# @code-hike/lighter

> Code Hike's syntax highlighter

Latest version **1.0.3** (published 2024-12-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install @code-hike/lighter
pnpm add @code-hike/lighter
yarn add @code-hike/lighter
bun add @code-hike/lighter
```

## Health

**Score 40/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2024-12-31 |
| First published | 2022-12-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | pomber |

## Links

- npm: https://www.npmjs.com/package/@code-hike/lighter
- Repository: https://github.com/code-hike/lighter
- Homepage: https://codehike.org
- Issues: https://github.com/code-hike/lighter/issues
- Funding: https://github.com/sponsors/code-hike
- npm.io page: https://npm.io/package/@code-hike/lighter

## Dependencies (2)

- [tm-grammars](https://npm.io/package/tm-grammars.md) ^1.22.0
- [ansi-sequence-parser](https://npm.io/package/ansi-sequence-parser.md) 1.1.1

## Recent versions

- 1.0.3 (latest) — 2024-12-31
- 1.0.0-beta.0 (beta) — 2024-08-02
- 1.0.2 — 2024-12-26
- 1.0.1 — 2024-10-17
- 1.0.0 — 2024-08-05
- 0.9.4 — 2024-07-13
- 0.9.3 — 2024-07-13
- 0.9.2 — 2024-07-13
- 0.9.1 — 2024-03-30
- 0.9.0 — 2023-10-11
- 0.8.2 — 2023-07-25
- 0.8.1 — 2023-07-17
- 0.8.0 — 2023-07-17
- 0.8.0-next.1 — 2023-07-17
- 0.8.0-next.0 — 2023-07-17
- … 51 more at https://npm.io/package/@code-hike/lighter/versions

## README

The syntax highlighter used by Code Hike.

## Usage

```js
import { highlight } from "@code-hike/lighter";

const { lines, style } = await highlight(
  /* code  */ "print('hello')",
  /* lang  */ "py",
  /* theme */ "github-dark"
);

// base foreground and background
const { color, background } = style;

console.log(lines);
```

Output:

```json
[
  [
    { "style": { "color": "#79C0FF" }, "content": "print" },
    { "style": { "color": "#C9D1D9" }, "content": "(" },
    { "style": { "color": "#A5D6FF" }, "content": "'hello'" },
    { "style": { "color": "#C9D1D9" }, "content": ")" }
  ]
]
```

For **dark/light theme support with CSS** see [#25](https://github.com/code-hike/lighter/pull/25)

For more theme colors (like line number foreground, selection background, etc.):

```js
import { getThemeColors } from "@code-hike/lighter";

const themeColors = await getThemeColors("material-darker");
```

## Credits

- Using [vscode-oniguruma](https://github.com/microsoft/vscode-oniguruma) for highlighting
- **Heavily inspired by [Shiki](https://github.com/shikijs/shiki)** and adapted to Code Hike needs.
- Some more inspiration from [starry-night](https://github.com/wooorm/starry-night)
- Grammars and some themes come from [Shiki](https://github.com/shikijs/shiki), which pulls them from different sources.

```

```

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