Skip to content

Commit e1c83a4

Browse files
authored
Merge pull request #256 from FormidableLabs/chore/local-dev
Add local development documentation and enable corepack
2 parents 67c7fbc + 27a0832 commit e1c83a4

File tree

3 files changed

+64
-18
lines changed

3 files changed

+64
-18
lines changed

README.md

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ _(If you just want to use your Prism CSS-file themes, that's also no problem)_
3939
## Table of Contents
4040

4141
<!-- 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-
4442

4543
- [Installation](#installation)
4644
- [Usage](#usage)
@@ -58,10 +56,18 @@ _(If you just want to use your Prism CSS-file themes, that's also no problem)_
5856
- [`getLineProps`](#getlineprops)
5957
- [`getTokenProps`](#gettokenprops)
6058
- [Utility Functions](#utility-functions)
61-
- [`normalizeTokens`](#normalizetokens)
6259
- [`useTokenize`](#usetokenize)
60+
- [`normalizeTokens`](#normalizetokens)
6361
- [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)
6571
- [LICENSE](#license)
6672
- [Maintenance Status](#maintenance-status)
6773

@@ -84,7 +90,8 @@ pnpm add prism-react-renderer
8490
> Prism React Renderer has a peer dependency on `react`
8591
8692
### 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).
8895

8996
```tsx
9097
import React from "react"
@@ -132,7 +139,7 @@ ReactDOM
132139

133140
### Custom Language Support
134141

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.
136143

137144
> _Note_: Some languages (such as Javascript) are part of the bundle of other languages
138145
@@ -327,12 +334,11 @@ Takes an array of Prism’s tokens and groups them by line, converting strings i
327334

328335
## Theming
329336

337+
### Using a built-in theme
338+
330339
The `defaultProps` you'd typically apply in a basic use-case, contain a default theme.
331340
This theme is [vsDark](./packages/prism-react-renderer/src/themes/vsDark.ts).
332341

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:
335-
336342
```jsx
337343
import { Highlight, themes } from 'prism-react-renderer';
338344

@@ -341,15 +347,13 @@ import { Highlight, themes } from 'prism-react-renderer';
341347

342348
These themes are JSON-based and are heavily inspired by VSCode's theme format.
343349

344-
Their syntax, expressed in Flow looks like the following:
345-
346-
```js
347-
{
348-
plain: StyleObj,
350+
```ts
351+
export type PrismTheme = {
352+
plain: PrismThemeEntry
349353
styles: Array<{
350-
types: string[],
351-
languages?: string[],
352-
style: StyleObj
354+
types: string[]
355+
style: PrismThemeEntry
356+
languages?: Language[]
353357
}>
354358
}
355359
```
@@ -368,6 +372,16 @@ property limits styles to highlighted languages.
368372
When converting a Prism CSS theme it's mostly just necessary to use classes as
369373
`types` and convert the declarations to object-style-syntax and put them on `style`.
370374
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+
<Highlight theme={emptyTheme} {/* ... */} />
383+
```
384+
371385
## Upgrade
372386

373387
If you are migrating from v1.x to v2.x, follow these steps
@@ -420,6 +434,37 @@ await import("prismjs/components/prism-applescript")
420434
require("prismjs/components/prism-applescript")
421435
```
422436

437+
## Development
438+
439+
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
457+
458+
```
459+
// terminal 1
460+
$ pnpm build:watch
461+
```
462+
463+
```
464+
// terminal 2
465+
$ pnpm start:demo
466+
```
467+
423468
## LICENSE
424469

425470
MIT

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@
5050
"patchedDependencies": {
5151
5252
}
53-
}
53+
},
54+
"packageManager": "[email protected]+sha512.7f6fda6e5e86c9cc4b815650b56036cc124a31772fd8bf3a1c6470278aa74b4da05732e0b457a00b6e6a58a16d52e9c263be06530c6ad80ef2180244c8eb8262"
5455
}

prism-react-renderer-Hero.png

-432 KB
Binary file not shown.

0 commit comments

Comments
 (0)