React component for code syntax highlighting. Preview 📕
Why another code syntax highlighting package?
npm install code-colors-react
import { ColorTokens } from "code-colors-react"; <pre> <ColorTokens code={"console.log('hello world');"} lang={"js"} /> </pre>;
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"
.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/prism-themes@1.9.0/themes/${theme}.min.css`; loadCss(url);
Basic JavaScript:
Negative values with red background:
Nested languages: JavaScript and CSS inside HTML:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4