Socket
Book a DemoInstallSign in
Socket

code-colors-react

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

code-colors-react

Code syntax highlighting React component

Source
npmnpm
Version
1.1.0
Version published
Weekly downloads
114
-34.48%
Maintainers
1
Weekly downloads
 
Created
Source

code-colors-react

React component for code syntax highlighting.

Why another code syntax highlighting package?

  • This package is simple to use. It is very lightweight, it essentially just ships a single React component.
  • The highlight.js dependency is loaded from CDN asynchronously.
  • highlight.js is run in a Web Worker, so it doesn't block the main thread.
  • 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.

Installation

npm i 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.
  • prefix — The prefix to use for the CSS classes. Defaults to hljs-.
  • 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 highlight.js.

You can do it in JavaScript like so:

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

const theme = 'github';
const href = `https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.8.0/build/styles/${theme}.min.css`;

loadCss(href, 'hljs');

Keywords

react

FAQs

Package last updated on 02 Jul 2023

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