Skip to content

aviadl/react-highlight

This branch is 1 commit ahead of, 43 commits behind akiran/react-highlight:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

fa3983e · Apr 3, 2016

History

39 Commits
Nov 28, 2015
Apr 3, 2016
Apr 3, 2016
Jul 12, 2015
Jul 12, 2015
Jul 12, 2015
Dec 8, 2014
Mar 2, 2016
Dec 16, 2014
Jul 12, 2015
Jul 12, 2015
Mar 2, 2016
Jul 12, 2015

Repository files navigation

react-highlight

React component for syntax highlighting using highlight.js

Build Status

Installation

  npm install react-highlight --save

Usage

Importing component

  var Highlight = require('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.

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>

About

React component for syntax highlighting

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%