A babel plugin to use PrismJS with standard bundlers.
Switch branches/tags
Clone or download
Latest commit 5e9aa31 Jun 15, 2018
Permalink
Failed to load latest commit information.
src Pass array to `insertAfter` instead of reverse May 27, 2018
test Add test for multiple languages Jun 15, 2018
.babelrc Initial commit May 24, 2018
.eslintignore Initial commit May 24, 2018
.eslintrc.js Initial commit May 24, 2018
.gitignore Initial commit May 24, 2018
.travis.yml Initial commit May 24, 2018
README.md Initial commit May 24, 2018
package-lock.json 1.0.2 Jun 15, 2018
package.json 1.0.2 Jun 15, 2018

README.md

babel-plugin-prismjs Build Status

A babel plugin to use PrismJS with standard bundlers.

How to Use

This plugin allows you to treat PrismJS as a standard module and configure what languages, plugins, & themes you want to bundle with Prism.

In your code, import prismjs:

import Prism from 'prismjs';

Prism.highlightAll();

The exported Prism object will be the fully-configured Prism instance.

Limitations

  • You must be using ES6 imports to load PrismJS.

Configuring the plugin

In your .babelrc, register the plugin and configure its dependencies:

{
  "plugins": [
    ["prismjs", {
        "languages": ["javascript", "css", "markup"],
        "plugins": ["line-numbers"],
        "theme": "twilight",
        "css": true
    }]
  ]
}

Each key are used as follows:

  • languages: Array of languages to include in the bundle. Those languages can be found here.
  • plugins: Array of plugins to include in the bundle. Those plugins can be found here.
  • theme: Name of theme to include in the bundle. Themes can be found here. Use lower-kebab-case for the theme name, e.g. solarized-light.
  • css: Boolean indicating whether to include .css files in the result. Defaults to false. If true, imports will be added for .css files. Must be true in order for theme to work.