WilcoFiers / react-prism

React.js + prismjs syntax hightlight component

Home Page:https://tomchentw.github.io/react-prism/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

react-prism

React.js + Prism.js syntax highlight component

Version Travis CI Quality Coverage Dependencies Gitter

Installation

npm i --save react-prism

Demo

Static hosted demo site on GitHub.

Example

Check src/app folder.

Usage

This module is intended to be bundled with webpack/browserify.

First, you have to include prismjs in your index.html:

<script src="path/to/your/prism.js"></script>

Why not require Prism by CommonJS? It's because prism.js will try to run itself as a Web Worker. It won't take affect if we require it into the source.

Then:

import {PrismCode} from "react-prism";

  // In a react component:
  render () {
    return (
      <PrismCode className="language-javascript">
        {require("raw-loader!./PrismCode")}
      </PrismCode>
    );
  }

Credits

About

React.js + prismjs syntax hightlight component

https://tomchentw.github.io/react-prism/

License:MIT License


Languages

Language:JavaScript 90.5%Language:HTML 9.0%Language:CSS 0.5%