Skip to content

Commit

Permalink
Use modern JavaScript in the NodeJS usage section (#1942)
Browse files Browse the repository at this point in the history
This updates the code examples in the NodeJS usage section to use modern JavaScript (ES6) features.
  • Loading branch information
RunDevelopment committed Sep 3, 2019
1 parent cc2cf3f commit 5c68a55
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,28 +194,28 @@ <h2>Usage with Node</h2>
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 <a href="https://www.ampproject.org/">AMP pages</a>.</p>

<p>Example:</p>
<pre><code class="language-js">var Prism = require('prismjs');
<pre><code class="language-js">const Prism = require('prismjs');

// The code snippet you want to highlight, as a string
var code = "var data = 1;";
const code = `var data = 1;`;

// Returns a highlighted HTML string
var html = Prism.highlight(code, Prism.languages.javascript, 'javascript');</code></pre>
const html = Prism.highlight(code, Prism.languages.javascript, 'javascript');</code></pre>

<p>Requiring <code>prismjs</code> will load the default languages: <code>markup</code>, <code>css</code>,
<code>clike</code> and <code>javascript</code>. You can load more languages with the
<code class="language-javascript">loadLanguages()</code> utility, which will automatically handle any required dependencies.</p>
<p>Example:</p>

<pre><code class="language-js">var Prism = require('prismjs');
var loadLanguages = require('prismjs/components/');
<pre><code class="language-js">const Prism = require('prismjs');
const loadLanguages = require('prismjs/components/');
loadLanguages(['haml']);

// The code snippet you want to highlight, as a string
var code = "= ['hi', 'there', 'reader!'].join \" \"";
const code = `= ['hi', 'there', 'reader!'].join " "`;

// Returns a highlighted HTML string
var html = Prism.highlight(code, Prism.languages.haml, 'haml');</code></pre>
const html = Prism.highlight(code, Prism.languages.haml, 'haml');</code></pre>

<p><strong>Note</strong>: Do <em>not</em> use <code class="language-javascript">loadLanguages()</code> with Webpack or another bundler, as this will cause Webpack to include all languages and plugins. Use the babel plugin described above.</p>

Expand Down

0 comments on commit 5c68a55

Please sign in to comment.