Skip to content

Commit 17e6f9f

Browse files
committed
Update readme and cleanup build tooling
1 parent efe9371 commit 17e6f9f

15 files changed

+132
-202
lines changed

.github/actions/setup/action.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Setup
2+
description: Setup Build Step
3+
inputs:
4+
node-version:
5+
required: true
6+
default: '18.x'
7+
8+
runs:
9+
using: "composite"
10+
steps:
11+
- uses: pnpm/action-setup@v3
12+
with:
13+
version: 8.2.0
14+
15+
- name: Use Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: ${{ inputs.node-version }}
19+
cache: 'pnpm'
20+
21+
- name: Install dependencies
22+
shell: bash
23+
run: pnpm install

.github/workflows/release.yml

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Prism React Renderer Release Workflow
1+
name: Release Workflow
22

33
on:
44
push:
@@ -19,25 +19,7 @@ jobs:
1919

2020
steps:
2121
- uses: actions/checkout@v4
22-
- uses: actions/setup-node@v4
23-
with:
24-
node-version: 18
25-
26-
- uses: pnpm/action-setup@v3
27-
with:
28-
version: 8.2.0
29-
- name: Get pnpm store directory
30-
id: pnpm-cache
31-
shell: bash
32-
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
33-
- uses: actions/cache@v4
34-
name: Setup pnpm cache
35-
with:
36-
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
37-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
38-
restore-keys: ${{ runner.os }}-pnpm-store-
39-
- name: Install dependencies
40-
run: pnpm install
22+
- uses: ./.github/actions/setup
4123

4224
- name: Build packages
4325
run: pnpm run build

.github/workflows/static-analysis.yml

+11-20
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ on:
55
branches:
66
- master
77
pull_request:
8-
workflow_dispatch:
8+
branches:
9+
- master
910

1011
jobs:
1112
static-analysis:
@@ -14,29 +15,19 @@ jobs:
1415

1516
steps:
1617
- uses: actions/checkout@v4
17-
- uses: actions/setup-node@v4
18-
with:
19-
node-version: 18
20-
21-
- uses: pnpm/action-setup@v3
22-
with:
23-
version: 8.2.0
24-
- name: Get pnpm store directory
25-
id: pnpm-cache
26-
shell: bash
27-
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
28-
- uses: actions/cache@v4
29-
name: Setup pnpm cache
30-
with:
31-
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
32-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
33-
restore-keys: ${{ runner.os }}-pnpm-store-
34-
- name: Install dependencies
35-
run: pnpm install
18+
- uses: ./.github/actions/setup
3619

3720
- name: Build library
3821
run: pnpm run build
22+
3923
- name: Type Check
4024
run: pnpm run typecheck
25+
4126
- name: Lint
4227
run: pnpm run lint
28+
29+
- name: Generate language definitions
30+
run: pnpm run build:languages
31+
32+
- name: Unit Test
33+
run: pnpm run test

.github/workflows/unit-test.yml

-42
This file was deleted.

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Formidable
3+
Copyright (c) 2018 Nearform
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+77-18
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
<a href="https://formidable.com/open-source/" target="_blank">
2-
<img alt="Prism React Renderer — Formidable, We build the modern web" src="https://raw.githubusercontent.com/FormidableLabs/prism-react-renderer/master/prism-react-renderer-Hero.png" />
1+
<a href="https://commerce.nearform.com/open-source/" target="_blank">
2+
<img alt="Prism React Renderer" src="https://oss.nearform.com/api/banner.svg?text=prism+react+renderer" />
33
</a>
44

55
<p align="center" style="font-size: 1.2rem;">
6-
A lean <a href="https://github.com/PrismJS/prism">Prism</a> highlighter component for React<br>
7-
Comes with everything to render Prismjs highlighted code directly to React (Native) elements, global-pollution-free!
6+
A lean <a href="https://github.com/PrismJS/prism">Prism</a> highlighter component for React
87
</p>
98

10-
[![Maintenance Status][maintenance-image]](#maintenance-status)
11-
## Why?
9+
<p align="center">
10+
<a href="https://npmjs.com/package/prism-react-renderer"><img src="https://img.shields.io/npm/dm/prism-react-renderer.svg"></a>
11+
<a href="https://npmjs.com/package/prism-react-renderer"><img src="https://img.shields.io/npm/v/prism-react-renderer.svg"></a>
12+
<a href="https://github.com/FormidableLabs/prism-react-renderer#maintenance-status">
13+
<img alt="Maintenance Status" src="https://img.shields.io/badge/maintenance-active-green.svg" />
14+
</a>
15+
</p>
1216

13-
Maybe you need to render some extra UI with your Prismjs-highlighted code,
14-
or maybe you'd like to manipulate what Prism renders completely,
15-
or maybe you're just using Prism with React and are searching for an easier,
16-
global-pollution-free way?
17+
<p align="center">
18+
Comes with everything to render Prismjs syntax highlighted code directly in React & React Native!
19+
</p>
1720

18-
Then you're right where you want to be!
21+
## Introduction
1922

20-
## How?
23+
Prism React Renderer powers syntax highlighting in the amazing [Docusaurus](https://docusaurus.io/) framework and many others.
2124

2225
This library tokenises code using Prism and provides a small render-props-driven
2326
component to quickly render it out into React. This is why it even works with
@@ -58,6 +61,7 @@ _(If you just want to use your Prism CSS-file themes, that's also no problem)_
5861
- [`normalizeTokens`](#normalizetokens)
5962
- [`useTokenize`](#usetokenize)
6063
- [Theming](#theming)
64+
- [Upgrading from v1 to v2](#upgrade)
6165
- [LICENSE](#license)
6266
- [Maintenance Status](#maintenance-status)
6367

@@ -121,14 +125,18 @@ export const App = () => (
121125
</Highlight>
122126
)
123127

124-
ReactDOM.createRoot(document.getElementById("root") as HTMLElement)
125-
.render(<App />)
126-
128+
ReactDOM
129+
.createRoot(document.getElementById("root") as HTMLElement)
130+
.render(<App />)
127131
```
128132

129133
### Custom Language Support
130134

131-
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. **Depending on your app's build system you may need to `await` the `import` or use `require` to ensure `window.Prism` exists before importing the custom languages.** You can add support for more by including their definitions from the main `prismjs` package:
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.
136+
137+
> _Note_: Some languages (such as Javascript) are part of the bundle of other languages
138+
139+
**Depending on your app's build system you may need to `await` the `import` or use `require` to ensure `window.Prism` exists before importing the custom languages.** You can add support for more by including their definitions from the main `prismjs` package:
132140

133141
```js
134142
import { Highlight, Prism } from "prism-react-renderer";
@@ -360,13 +368,64 @@ property limits styles to highlighted languages.
360368
When converting a Prism CSS theme it's mostly just necessary to use classes as
361369
`types` and convert the declarations to object-style-syntax and put them on `style`.
362370

371+
## Upgrade
372+
373+
If you are migrating from v1.x to v2.x, follow these steps
374+
375+
### Change module imports
376+
377+
```diff
378+
- import Highlight, { defaultProps } from "prism-react-renderer";
379+
+ import { Highlight } from "prism-react-renderer"
380+
381+
const Content = (
382+
- <Highlight {...defaultProps} code={exampleCode} language="jsx">
383+
+ <Highlight code={exampleCode} language="jsx">
384+
```
385+
386+
### Change theme imports
387+
388+
```diff
389+
- const theme = require('prism-react-renderer/themes/github')
390+
+ const theme = require('prism-react-renderer').themes.github
391+
```
392+
393+
### Check language support
394+
395+
> By default prism-react-renderer only includes a base set of languages that Prism supports. Depending on your app's build system you may need to await the import or use require to ensure window.Prism exists before importing the custom languages.
396+
397+
See: https://github.com/FormidableLabs/prism-react-renderer#custom-language-support
398+
399+
Install prismjs (if not available yet):
400+
401+
```
402+
# npm
403+
npm install --save prismjs
404+
# yarn
405+
yarn add prismjs
406+
# pnpm
407+
pnpm add prismjs
408+
```
409+
410+
### Add language component
411+
412+
If the language is not already bundled in the above, you can add additional languages with the following code:
413+
414+
```
415+
import { Highlight, Prism } from "prism-react-renderer";
416+
417+
(typeof global !== "undefined" ? global : window).Prism = Prism
418+
await import("prismjs/components/prism-applescript")
419+
/** or **/
420+
require("prismjs/components/prism-applescript")
421+
```
422+
363423
## LICENSE
364424

365425
MIT
366426

367427
## Maintenance Status
368428

369-
**Active:** Formidable is actively working on this project, and we expect to continue for work for the foreseeable future. Bug reports, feature requests and pull requests are welcome.
429+
**Active:** Nearform is actively working on this project, and we expect to continue work for the foreseeable future. Bug reports, feature requests and pull requests are welcome.
370430

371431
[maintenance-image]: https://img.shields.io/badge/maintenance-active-green.svg
372-

packages/demo/index.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
<html lang="en">
33
<head>
44
<meta charset="UTF-8" />
5-
<link rel="icon" type="image/svg+xml" href="/formidable-icon.svg" />
5+
<link rel="icon" type="image/svg+xml" href="/nearform-icon.svg" />
66
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
77
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono&display=swap" rel="stylesheet">
8-
<title>Formidable – Prism React Renderer Demo</title>
8+
<title>Prism React Renderer Demo</title>
99
</head>
1010
<body>
1111
<div id="root"></div>

packages/demo/public/formidable-icon.svg

-37
This file was deleted.

packages/demo/public/formidable-wordmark.svg

-54
This file was deleted.

0 commit comments

Comments
 (0)