Socket
Book a DemoInstallSign in
Socket

code-colors

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

code-colors

Code syntax highlighting for the web

latest
Source
npmnpm
Version
2.4.0
Version published
Weekly downloads
173
39.52%
Maintainers
1
Weekly downloads
 
Created
Source

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.

FAQs

Package last updated on 30 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts