akiran/react-highlight
关于
用于语法高亮的 React 组件
网站与应用开发实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- 0
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文react-highlight
React component for syntax highlighting using highlight.js
Latest version
0.11.1
Documentation
CodeSandbox Example
Installation
npm install react-highlight --save
Usage
Importing component
import Highlight from 'react-highlight'
Adding styles
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:
- 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.
<Highlight className='language-name-of-snippet'>
{"code snippet to be highlighted"}
</Highlight>
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.
<Highlight innerHTML={true}>
{"html with multiple code snippets"}
</Highlight>
探索相关项目
加载中…