|
| 1 | +## Highlight Code for React |
| 2 | + |
| 3 | + only one prop to show highlightCode using highlight.js |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +<p> |
| 8 | + <a href="https://npm-stat.com/charts.html?package=react-highlight-code"> |
| 9 | + <img alt="Downloads" src="https://img.shields.io/npm/dm/react-highlight-code.svg"> |
| 10 | + </a> |
| 11 | + <a href="https://npmjs.com/package/react-highlight-code"> |
| 12 | + <img alt="Version" src="https://img.shields.io/npm/v/react-highlight-code.svg"/> |
| 13 | + </a> |
| 14 | + <a href="http://packagequality.com/#?package=react-highlight-code"> |
| 15 | + <img alt="Quality" src="https://npm.packagequality.com/shield/react-highlight-code.svg"> |
| 16 | + </a> |
| 17 | +</p> |
| 18 | + |
| 19 | + |
| 20 | +``` |
| 21 | +yarn add highlight.js react-highlight-code |
| 22 | +``` |
| 23 | + |
| 24 | +## live demo |
| 25 | + |
| 26 | +[stackblitz highlight demo](https://stackblitz.com/github/F-one-1/react-highlight-code?file=src%2FApp.jsx) |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +### 1. use in react |
| 31 | + |
| 32 | +Install the `react-highlight-code` and `highlight.js`: |
| 33 | + |
| 34 | +import the component and style |
| 35 | + |
| 36 | +```js |
| 37 | +import { HighCode } from 'react-highlight-code' |
| 38 | +import 'react-highlight-code/dist/style.css' |
| 39 | +const value = 'only one prop to show highlightCode using highlight.js' |
| 40 | +<HighCode codeValue={value}></HighCode> |
| 41 | +``` |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +### Component Props |
| 48 | + |
| 49 | +| prop | description | type | default | |
| 50 | +| :-------------- | :---------------------------------------------- | :-------- | :----------------------------------------------------- | |
| 51 | +| codeValue | Highlight Code Source | `String` | `''` | |
| 52 | +| lang | Highlight Code Type | `String` | `javascript` (such as 'javascript','vue','html','css') | |
| 53 | +| theme | Component Highlight Code theme | `String` | default: `dark`(only ['dark','light']) | |
| 54 | +| codeLines | Show Code lines | `Boolean` | `false` | |
| 55 | +| langName | Highlight Code Name (Upper left corner display) | `String` | `` | |
| 56 | +| width | component style width | `String` | `620px` | |
| 57 | +| height | component style height | `String` | `` | |
| 58 | +| maxWidth | component style max-width | `String` | `` | |
| 59 | +| maxHight | component style max-height`String` | `String` | `200px` | |
| 60 | +| fontSize | highlight code font-size | `Number` | - | |
| 61 | +| scrollStyleBool | component scroll bar style | `Boolean` | `true` | |
| 62 | +| copy | whether the code can copy and show | `Boolean` | `true` | |
0 commit comments