react-highlight

React component for syntax highlighting

  • 所有者: akiran/react-highlight
  • 平台:
  • 许可证: MIT License
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

react-highlight

React component for syntax highlighting using highlight.js

Build Status

Latest version

0.11.1

Documentation

CodeSandbox Example

Edit new

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>

主要指标

概览
名称与所有者akiran/react-highlight
主编程语言JavaScript
编程语言JavaScript (语言数: 1)
平台
许可证MIT License
所有者活动
创建于2014-12-08 15:53:16
推送于2022-11-17 15:06:14
最后一次提交2022-11-17 20:36:09
发布数0
用户参与
星数769
关注者数11
派生数86
提交数81
已启用问题?
问题数61
打开的问题数24
拉请求数9
打开的拉请求数5
关闭的拉请求数15
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?