From 1e99e961ddb62c66f4a044f53dde6c202ae7b53a Mon Sep 17 00:00:00 2001
From: mAAdhaTTah Basic usage
Example:
<script src="prism.js" data-manual></script>
- If you want to use Prism on the server or through the command line, Prism can be used with Node.js as well. - This might be useful if you're trying to generate static HTML pages with highlighted code for environments that don't support browser-side JS, like AMP pages.
+You can install Prism for Node.js by running:
-$ npm install prismjs
+ If you want to use Prism with a bundler, install Prism with npm
:
Example:
-var Prism = require('prismjs');
+ $ npm install prismjs
+
+ You can then import
into your bundle:
+
+ import Prism from 'prismjs';
+
+ To make it easy to configure your Prism instance with only the languages and plugins you need, use the babel plugin,
+ babel-plugin-prismjs. This will allow you to load
+ the minimum number of languages and plugins to satisfy your needs.
+ See that plugin's documentation for configuration details.
+
+ Usage with Node
+
+ If you want to use Prism on the server or through the command line, Prism can be used with Node.js as well.
+ This might be useful if you're trying to generate static HTML pages with highlighted code for environments that don't support browser-side JS, like AMP pages.
+
+ Example:
+ var Prism = require('prismjs');
// The code snippet you want to highlight, as a string
var code = "var data = 1;";
@@ -169,13 +183,12 @@ Basic usage
var html = Prism.highlight(code, Prism.languages.javascript, 'javascript');
Requiring prismjs
will load the default languages: markup
, css
,
- clike
and javascript
. You can load more languages separately by requiring them
- directly from the components
folder. Or you can use the loadLanguages()
utility, that
- will automatically handle any required dependencies.
+ clike
and javascript
. You can load more languages with the
+ loadLanguages()
utility, which will automatically handle any required dependencies.
Example:
var Prism = require('prismjs');
-var loadLanguages = require('prismjs/components/index.js');
+var loadLanguages = require('prismjs/components');
loadLanguages(['haml']);
// The code snippet you want to highlight, as a string
@@ -184,6 +197,8 @@ Basic usage
// Returns a highlighted HTML string
var html = Prism.highlight(code, Prism.languages.haml, 'haml');
+ Note: Do not use loadLanguages()
with Webpack or another bundler, as this will cause Webpack to include all languages and plugins. Use the babel plugin described above.
+