2.3.1 • Published 8 months ago

code-colors v2.3.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
8 months ago

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.3.1

8 months ago

2.3.0

1 year ago

2.2.0

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago