- A lean Prism highlighter component for React
- Comes with everything to render Prismjs highlighted code directly to React (Native) elements, global-pollution-free!
+ A lean Prism highlighter component for React
-Maybe you need to render some extra UI with your Prismjs-highlighted code,
-or maybe you'd like to manipulate what Prism renders completely,
-or maybe you're just using Prism with React and are searching for an easier,
-global-pollution-free way?
+
+ Comes with everything to render Prismjs syntax highlighted code directly in React & React Native!
+
-Then you're right where you want to be!
+## Introduction
-## How?
+Prism React Renderer powers syntax highlighting in the amazing [Docusaurus](https://docusaurus.io/) framework and many others.
This library tokenises code using Prism and provides a small render-props-driven
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)_
- [`normalizeTokens`](#normalizetokens)
- [`useTokenize`](#usetokenize)
- [Theming](#theming)
+- [Upgrading from v1 to v2](#upgrade)
- [LICENSE](#license)
- [Maintenance Status](#maintenance-status)
@@ -121,14 +125,18 @@ export const App = () => (
)
-ReactDOM.createRoot(document.getElementById("root") as HTMLElement)
- .render()
-
+ReactDOM
+ .createRoot(document.getElementById("root") as HTMLElement)
+ .render()
```
### Custom Language Support
-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:
+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.
+
+> _Note_: Some languages (such as Javascript) are part of the bundle of other languages
+
+**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:
```js
import { Highlight, Prism } from "prism-react-renderer";
@@ -256,7 +264,7 @@ advisable.
#### `getLineProps`
You need to add a `line` property (type: `Token[]`) to the object you're passing to
-`getLineProps`; It's also advisable to add a `key`.
+`getLineProps`.
This getter will return you props to spread onto your line elements (typically `
s`).
@@ -269,7 +277,7 @@ The `className` will always contain `.token-line`.
#### `getTokenProps`
You need to add a `token` property (type: `Token`) to the object you're passing to
-`getTokenProps`; It's also advisable to add a `key`.
+`getTokenProps`.
This getter will return you props to spread onto your token elements (typically `s`).
@@ -360,13 +368,64 @@ property limits styles to highlighted languages.
When converting a Prism CSS theme it's mostly just necessary to use classes as
`types` and convert the declarations to object-style-syntax and put them on `style`.
+## Upgrade
+
+If you are migrating from v1.x to v2.x, follow these steps
+
+### Change module imports
+
+```diff
+- import Highlight, { defaultProps } from "prism-react-renderer";
++ import { Highlight } from "prism-react-renderer"
+
+const Content = (
+-
++
+```
+
+### Change theme imports
+
+```diff
+- const theme = require('prism-react-renderer/themes/github')
++ const theme = require('prism-react-renderer').themes.github
+```
+
+### Check language support
+
+> 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.
+
+See: https://github.com/FormidableLabs/prism-react-renderer#custom-language-support
+
+Install prismjs (if not available yet):
+
+```
+# npm
+npm install --save prismjs
+# yarn
+yarn add prismjs
+# pnpm
+pnpm add prismjs
+```
+
+### Add language component
+
+If the language is not already bundled in the above, you can add additional languages with the following code:
+
+```
+import { Highlight, Prism } from "prism-react-renderer";
+
+(typeof global !== "undefined" ? global : window).Prism = Prism
+await import("prismjs/components/prism-applescript")
+/** or **/
+require("prismjs/components/prism-applescript")
+```
+
## LICENSE
MIT
## Maintenance Status
-**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.
+**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.
[maintenance-image]: https://img.shields.io/badge/maintenance-active-green.svg
-
diff --git a/packages/demo/index.html b/packages/demo/index.html
index d42d119..c20c08d 100644
--- a/packages/demo/index.html
+++ b/packages/demo/index.html
@@ -2,10 +2,10 @@
-
+
- Formidable – Prism React Renderer Demo
+ Prism React Renderer Demo
diff --git a/packages/demo/public/formidable-icon.svg b/packages/demo/public/formidable-icon.svg
deleted file mode 100644
index b1beef1..0000000
--- a/packages/demo/public/formidable-icon.svg
+++ /dev/null
@@ -1,37 +0,0 @@
-
-
-
diff --git a/packages/demo/public/formidable-wordmark.svg b/packages/demo/public/formidable-wordmark.svg
deleted file mode 100644
index 8c81362..0000000
--- a/packages/demo/public/formidable-wordmark.svg
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
-
diff --git a/packages/demo/public/nearform-icon.svg b/packages/demo/public/nearform-icon.svg
new file mode 100644
index 0000000..4e95a02
--- /dev/null
+++ b/packages/demo/public/nearform-icon.svg
@@ -0,0 +1,4 @@
+
diff --git a/packages/demo/public/nearform-logo-white.svg b/packages/demo/public/nearform-logo-white.svg
new file mode 100644
index 0000000..cd49ab3
--- /dev/null
+++ b/packages/demo/public/nearform-logo-white.svg
@@ -0,0 +1,4 @@
+
diff --git a/packages/demo/src/App.tsx b/packages/demo/src/App.tsx
index 957fb9e..372ccec 100644
--- a/packages/demo/src/App.tsx
+++ b/packages/demo/src/App.tsx
@@ -26,9 +26,9 @@ function App() {