GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - streamich/code-colors-react: Code syntax highlighting React component

BranchesTags
Open more actions menu

Latest commit

 

History

146 Commits
146 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.storybook
.storybook
 
 
src
src
 
 
.babelrc.json
.babelrc.json
 
 
.gitignore
.gitignore
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package.json
package.json
 
 
tsconfig.build.json
tsconfig.build.json
 
 
tsconfig.json
tsconfig.json
 
 
yarn.lock
yarn.lock
 
 

Repository files navigation

code-colors-react

React component for code syntax highlighting. Preview 📕

Why another code syntax highlighting package?

  • A simple to use React component.
  • It is very lightweight, only ships a small React component, which loads tokenization script (~35Kb) in a Web Worker on demand, on first usage.
  • The Prism.js tokenization script is loaded from the CDN asynchronously.
  • Runs tokenization in a Web Worker, so it doesn't block the main thread.
  • Emits Prism.js compatible HTML, so you can use any Prism.js themes.
  • No layout shifts before the code is highlighted. While the code is being highlighted in the Web Worker, the component renders plain text with the correct dimensions.
  • If code changes while it is being highlighted, the component will cancel the previous highlighting and start a new one.
  • Interactive CSS on mouse hover.

Installation

npm install code-colors-react

Usage

import { ColorTokens } from "code-colors-react";

<pre>
  <ColorTokens code={"console.log('hello world');"} lang={"js"} />
</pre>;

Props

  • code — The code to highlight.
  • lang — The language of the code. If omitted, it will try to autodetect the language.
  • as — The root element to render. Defaults to "code".

Styling

To style the highlighted code, you can use any of the pre-defined themes from Prism.

You can do it in JavaScript like so:

import { loadCss } from "thingies/lib/loadCss";

const theme = "github";
const url = `https://cdn.jsdelivr.net/npm/[email protected]/themes/${theme}.min.css`;

loadCss(url);

Examples

Basic JavaScript:

image

Negative values with red background:

image

Nested languages: JavaScript and CSS inside HTML:

image

See more examples.

About

Code syntax highlighting React component

streamich.github.io/code-colors-react/

Topics

codecolorcomponenthighlightprereactsyntax

Resources

Readme
Apache-2.0 license
Activity

Stars

7 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Sponsor this project

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.