Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akiran/react-highlight
React component for syntax highlighting
https://github.com/akiran/react-highlight
Last synced: about 4 hours ago
JSON representation
React component for syntax highlighting
- Host: GitHub
- URL: https://github.com/akiran/react-highlight
- Owner: akiran
- License: mit
- Created: 2014-12-08T15:53:16.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2022-11-17T15:06:14.000Z (about 2 years ago)
- Last Synced: 2024-05-01T21:29:54.233Z (8 months ago)
- Language: JavaScript
- Homepage: https://react-highlight.neostack.com/
- Size: 47.9 KB
- Stars: 760
- Watchers: 12
- Forks: 100
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# react-highlight
React component for syntax highlighting using highlight.js
![Build Status](https://travis-ci.org/akiran/react-highlight.svg?branch=master)
### Latest version
`0.11.1`
## [Documentation](https://react-highlight.neostack.com/)
### CodeSandbox Example
[![Edit new](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/mj6wlmor9p)
### Installation
```bash
npm install react-highlight --save
```### Usage
#### Importing component
```js
import Highlight from 'react-highlight'
```#### Adding styles
Choose the [theme](https://highlightjs.org/static/demo/) for syntax highlighting and add corresponding styles of highlight.js
```css
```The styles will most likely be in `node_modules/highlight.js/styles` folder.
Props:
* className: custom class name
* innerHTML: enable to render markup with dangerouslySetInnerHTML
* element: render code snippet inside specified element#### Syntax highlighting of single code snippet
Code snippet that requires syntax highlighting should be passed as children to Highlight component in string format. Language name of code snippet should be specified as className.
```html
{"code snippet to be highlighted"}
```
#### Syntax highlighting of mutiple code snippets
Set `innerHTML=true` to highlight multiple code snippets at a time.
This is especially usefull if html with multiple code snippets is generated from preprocesser tools like markdown.**Warning:** If innerHTML is set to true, make sure the html generated with code snippets is from trusted source.
```html
{"html with multiple code snippets"}
```