You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+62-17Lines changed: 62 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -39,8 +39,6 @@ _(If you just want to use your Prism CSS-file themes, that's also no problem)_
39
39
## Table of Contents
40
40
41
41
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
42
-
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
43
-
44
42
45
43
-[Installation](#installation)
46
44
-[Usage](#usage)
@@ -58,10 +56,18 @@ _(If you just want to use your Prism CSS-file themes, that's also no problem)_
58
56
-[`getLineProps`](#getlineprops)
59
57
-[`getTokenProps`](#gettokenprops)
60
58
-[Utility Functions](#utility-functions)
61
-
-[`normalizeTokens`](#normalizetokens)
62
59
-[`useTokenize`](#usetokenize)
60
+
-[`normalizeTokens`](#normalizetokens)
63
61
-[Theming](#theming)
64
-
-[Upgrading from v1 to v2](#upgrade)
62
+
-[Using a built-in theme](#using-a-built-in-theme)
63
+
-[Providing a CSS based theme](#providing-a-css-based-theme)
64
+
-[Upgrade](#upgrade)
65
+
-[Change module imports](#change-module-imports)
66
+
-[Change theme imports](#change-theme-imports)
67
+
-[Check language support](#check-language-support)
68
+
-[Add language component](#add-language-component)
69
+
-[Development](#development)
70
+
-[Local Demo](#local-demo)
65
71
-[LICENSE](#license)
66
72
-[Maintenance Status](#maintenance-status)
67
73
@@ -84,7 +90,8 @@ pnpm add prism-react-renderer
84
90
> Prism React Renderer has a peer dependency on `react`
85
91
86
92
### Usage
87
-
Prism React Renderer has a named export for the `<Highlight />` component along with `themes`. To see Prism React Render in action with base styling check out `packages/demo` or run `pnpm run start:demo` from the root of this repository.
93
+
94
+
Prism React Renderer has a named export for the `<Highlight />` component along with `themes`. To see Prism React Render in action with base styling, clone the repo and follow the [steps for local development](#development).
88
95
89
96
```tsx
90
97
importReactfrom"react"
@@ -132,7 +139,7 @@ ReactDOM
132
139
133
140
### Custom Language Support
134
141
135
-
By default `prism-react-renderer` only includes a [base set of languages](https://github.com/FormidableLabs/prism-react-renderer/blob/c914fdea48625ba59c8022174bb3df1ed802ce4d/packages/generate-prism-languages/index.ts#L9-L23) that Prism supports.
142
+
By default `prism-react-renderer` only includes a [base set of languages](https://github.com/FormidableLabs/prism-react-renderer/blob/master/packages/generate-prism-languages/index.ts#L9-L23) that Prism supports.
136
143
137
144
> _Note_: Some languages (such as Javascript) are part of the bundle of other languages
138
145
@@ -327,12 +334,11 @@ Takes an array of Prism’s tokens and groups them by line, converting strings i
327
334
328
335
## Theming
329
336
337
+
### Using a built-in theme
338
+
330
339
The `defaultProps` you'd typically apply in a basic use-case, contain a default theme.
331
340
This theme is [vsDark](./packages/prism-react-renderer/src/themes/vsDark.ts).
332
341
333
-
While all `className`s are provided with `<Highlight />`, so that you could use your good
334
-
old Prism CSS-file themes, you can also choose to use `prism-react-renderer`'s themes like so:
These themes are JSON-based and are heavily inspired by VSCode's theme format.
343
349
344
-
Their syntax, expressed in Flow looks like the following:
345
-
346
-
```js
347
-
{
348
-
plain: StyleObj,
350
+
```ts
351
+
exporttypePrismTheme= {
352
+
plain:PrismThemeEntry
349
353
styles:Array<{
350
-
types: string[],
351
-
languages?: string[],
352
-
style: StyleObj
354
+
types:string[]
355
+
style:PrismThemeEntry
356
+
languages?:Language[]
353
357
}>
354
358
}
355
359
```
@@ -368,6 +372,16 @@ property limits styles to highlighted languages.
368
372
When converting a Prism CSS theme it's mostly just necessary to use classes as
369
373
`types` and convert the declarations to object-style-syntax and put them on `style`.
370
374
375
+
### Providing a CSS based theme
376
+
377
+
In order to use a CSS based theme like the ones from [PrismJS](https://github.com/PrismJS/prism-themes), you need to disable the built in theme.
378
+
379
+
```ts
380
+
const emptyTheme = { plain: {}, styles: [] };
381
+
382
+
<Highlighttheme={emptyTheme} {/* ... */} />
383
+
```
384
+
371
385
## Upgrade
372
386
373
387
If you are migrating from v1.x to v2.x, follow these steps
Local development setup can be run with the following commands running Node 18.x. This project uses corepack to specify its package manager version and you should have it enabled locally using `corepack enable`.
440
+
441
+
```
442
+
$ pnpm install
443
+
$ pnpm build
444
+
$ pnpm test
445
+
```
446
+
447
+
### Local Demo
448
+
449
+
To run the local demo, ensure you have first run `pnpm build`, then run `pnpm start:demo` and open the provided URL to the demo site in your terminal.
450
+
451
+
```
452
+
$ pnpm build
453
+
$ pnpm start:demo
454
+
```
455
+
456
+
The workspace projects are linked, so changes can be hot reloaded during development by running multiple terminals
0 commit comments