akiran/react-highlight(opens in a new tab)
Language: JavaScript
React component for syntax highlighting
- stars
- 761
- watchers
- 9
- forks
- 81
- open issues
- 29
- Last updated
- 11/18/2022
Language: JavaScript
React component for syntax highlighting
React component for syntax highlighting using highlight.js
0.11.1
npm install react-highlight --save
import Highlight from 'react-highlight'
Choose the theme for syntax highlighting and add corresponding styles of highlight.js
<link rel="stylesheet" href="/path/to/styles/theme-name.css">
The styles will most likely be in node_modules/highlight.js/styles folder.
Props:
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.
<Highlight className='language-name-of-snippet'> {"code snippet to be highlighted"} </Highlight>
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.
<Highlight innerHTML={true}> {"html with multiple code snippets"} </Highlight>