code-colors

Code syntax highlighting for the web

Apache-2.0 12 个版本
安装
npm install code-colors
yarn add code-colors
pnpm add code-colors
bun add code-colors
README

code-colors

Code syntax highlighting for the web. Uses Prism for parsing.

Why I created this library? I needed a simple React component that highlights code, but there was none which satisfied the following requirements:

  • Dynamically loads highligting parsers.
  • Executs highlighting in a web worker.
  • While code is parsed in the worker, renders raw un-highlighted source without any flickering.
  • A simple to use React component.

Installation

npm install code-colors

Usage

Simply call the tokenizeAsync function with the code and language you want to highlight.

import {tokenizeAsync} from 'code-colors';

const code = `console.log('Hello, World!');`;
const language = 'javascript';

const tokens = await tokenizeAsync(code, language);
console.log(tokens);

It will automatically download popular Prism languages from the CDN.

版本列表
2.5.0 2026-04-27
2.4.0 2025-08-30
2.3.1 2024-10-10
2.3.0 2024-05-30
2.2.0 2024-05-25
2.1.0 2024-05-24
2.0.1 2024-05-23
2.0.0 2024-05-21
1.3.0 2023-07-02
1.2.0 2023-07-02
1.1.0 2023-07-02
1.0.0 2023-07-02