-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from streamich/bump-code-colors
Bump `code-colors`
- Loading branch information
Showing
7 changed files
with
3,104 additions
and
3,625 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,17 @@ 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. | ||
- 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](https://cdn.jsdelivr.net/npm/[email protected]/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. | ||
|
||
## Installation | ||
|
||
|
@@ -31,21 +36,20 @@ import { ColorTokens } from "code-colors-react"; | |
|
||
- `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](https://cdn.jsdelivr.net/gh/highlightjs/[email protected].0/build/styles/) from | ||
`highlight.js`. | ||
To style the highlighted code, you can use any of the [pre-defined themes](https://cdn.jsdelivr.net/npm/[email protected].0/themes/) from | ||
Prism. | ||
|
||
You can do it in JavaScript like so: | ||
|
||
```js | ||
import { loadCss } from "thingies/lib/loadCss"; | ||
|
||
const theme = "github"; | ||
const href = `https://cdn.jsdelivr.net/gh/highlightjs/[email protected].0/build/styles/${theme}.min.css`; | ||
const href = `https://cdn.jsdelivr.net/npm/[email protected].0/themes/${theme}.min.css`; | ||
|
||
loadCss(href, "hljs"); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.