Debian Codegraph @

index.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4
5 <script>
6 // Just a lil’ script to show off that inline JS gets highlighted
7 window.console && console.log('foo');
8 </script>
9 <meta charset="utf-8" />
10 <link rel="icon" href="assets/favicon.png" />
11 <title>Prism</title>
12 <link rel="stylesheet" href="assets/style.css" />
13 <link rel="stylesheet" href="themes/prism.css" data-noprefix />
14 <script src="assets/vendor/prefixfree.min.js"></script>
15
16 <script>var _gaq = [['_setAccount', 'UA-33746269-1'], ['_trackPageview']];</script>
17 <script src="https://www.google-analytics.com/ga.js" async></script>
18 </head>
19 <body>
20
21 <header>
22 <div class="intro" data-src="assets/templates/header-main.html" data-type="text/html"></div>
23
24 <ul id="features">
25 <li>
26 <strong>Dead simple</strong>
27 Include prism.css and prism.js, use proper HTML5 code tags (<code>code.language-xxxx</code>), done!
28 </li>
29 <li>
30 <strong>Intuitive</strong>
31 Language classes are inherited so you can only define the language once for multiple code snippets.
32 </li>
33 <li>
34 <strong>Light as a feather</strong>
35 The core is 2KB minified &amp; gzipped. Languages add 0.3-0.5KB each, themes are around 1KB.
36 </li>
37 <li>
38 <strong>Blazing fast</strong>
39 Supports parallelism with Web Workers, if available.
40 </li>
41 <li>
42 <strong>Extensible</strong>
43 Define new languages or extend existing ones.
44 Add new features thanks to Prism’s plugin architecture.
45 </li>
46 <li>
47 <strong>Easy styling</strong>
48 All styling is done through CSS, with sensible class names like <code>.comment</code>, <code>.string</code>, <code>.property</code> etc
49 </li>
50 </ul>
51
52 </header>
53
54 <section id="used-by">
55 <h1>Used By</h1>
56
57 <p>Prism is used on several websites, small and large. Some of them are:</p>
58
59 <div class="used-by-logos">
60 <a href="https://www.smashingmagazine.com/" target="_blank"><img src="assets/img/logo-smashing.png" alt="Smashing Magazine" /></a>
61 <a href="https://alistapart.com/" target="_blank"><img src="assets/img/logo-ala.png" alt="A List Apart" /></a>
62 <a href="https://developer.mozilla.org/" target="_blank"><img src="assets/img/logo-mdn.png" alt="Mozilla Developer Network (MDN)" /></a>
63 <a href="https://css-tricks.com/" target="_blank"><img src="assets/img/logo-css-tricks.png" alt="CSS-Tricks" /></a>
64 <a href="https://www.sitepoint.com/" target="_blank"><img src="assets/img/logo-sitepoint.png" alt="SitePoint" /></a>
65 <a href="https://www.drupal.org/" target="_blank"><img src="assets/img/logo-drupal.png" alt="Drupal" /></a>
66 <a href="https://reactjs.org/" target="_blank"><img src="assets/img/logo-react.png" alt="React" /></a>
67 <a href="https://stripe.com/" target="_blank"><img src="assets/img/logo-stripe.png" alt="Stripe" /></a>
68 <a href="https://dev.mysql.com/" target="_blank"><img src="assets/img/logo-mysql.png" alt="MySQL" /></a>
69 </div>
70 </section>
71
72 <section id="examples">
73 <h1>Examples</h1>
74
75 <p>The Prism source, highlighted with Prism (don’t you just love how meta this is?):</p>
76 <pre data-src="prism.js"></pre>
77
78 <p>This page’s CSS code, highlighted with Prism:</p>
79 <pre data-src="assets/style.css"></pre>
80
81 <p>This page’s HTML, highlighted with Prism:</p>
82 <pre data-src="index.html"></pre>
83
84 <p>This page’s logo (SVG), highlighted with Prism:</p>
85 <pre data-src="assets/logo.svg"></pre>
86
87 <p>If you’re still not sold, you can <a href="examples.html">view more examples</a> or <a href="test.html">try it out for yourself</a>.</p>
88 </section>
89
90 <section id="features-full" class="language-markup">
91 <h1>Full list of features</h1>
92 <ul>
93 <li><strong>Only 2KB</strong> minified &amp; gzipped (core). Each language definition adds roughly 300-500 bytes.</li>
94 <li>Encourages good author practices. Other highlighters encourage or even force you to use elements that are semantically wrong,
95 like <code>&lt;pre></code> (on its own) or <code>&lt;script></code>.
96 Prism forces you to use the correct element for marking up code: <code>&lt;code></code>.
97 On its own for inline code, or inside a <code>&lt;pre></code> for blocks of code.
98 In addition, the language is defined through the way recommended in the HTML5 draft: through a <code>language-xxxx</code> class.</li>
99 <li>The <code>language-xxxx</code> class is inherited.
100 This means that if multiple code snippets have the same language, you can just define it once,in one of their common ancestors.</li>
101 <li>Supports <strong>parallelism with Web Workers</strong>, if available.
102 Disabled by default (<a href="faq.html#why-is-asynchronous-highlighting-disabled-by-default">why?</a>).</li>
103 <li>Very easy to extend without modifying the code, due to Prism’s <a href="#plugins">plugin architecture</a>.
104 Multiple hooks are scattered throughout the source.</li>
105 <li>Very easy to <a href="extending.html#language-definitions">define new languages</a>.
106 The only thing you need is a good understanding of regular expressions.</li>
107 <li>All styling is done through CSS, with <a href="faq.html#how-do-i-know-which-tokens-i-can-style-for">sensible class names</a> rather than ugly, namespaced, abbreviated nonsense.</li>
108 <li>Wide browser support: Edge, IE11, Firefox, Chrome, Safari, <a href="faq.html#this-page-doesnt-work-in-opera">Opera</a>, most mobile browsers.</li>
109 <li>Highlights embedded languages (e.g. CSS inside HTML, JavaScript inside HTML).</li>
110 <li>Highlights inline code as well, not just code blocks.</li>
111 <li>It doesn’t force you to use any Prism-specific markup, not even a Prism-specific class name, only standard markup you should be using anyway.
112 So, you can just try it for a while, remove it if you don’t like it and leave no traces behind.</li>
113 <li>Highlight specific lines and/or line ranges (requires <a href="plugins/line-highlight/">plugin</a>).</li>
114 <li>Show invisible characters like tabs, line breaks etc (requires <a href="plugins/show-invisibles/">plugin</a>).</li>
115 <li>Autolink URLs and emails, use Markdown links in comments (requires <a href="plugins/autolinker/">plugin</a>).</li>
116 </ul>
117 </section>
118
119 <section id="limitations">
120 <h1>Limitations</h1>
121 <ul>
122 <li>Any pre-existing HTML in the code will be stripped off. <a href="faq.html#if-pre-existing-html-is-stripped-off-how-can-i-highlight">There are ways around it though</a>.</li>
123 <li>Regex-based so it *will* fail on certain edge cases, which are documented in the <a href="known-failures.html">known failures page</a>.</li>
124 <li>Some of our themes have problems with certain layouts. Known cases are documented <a href="known-failures.html#themes">here</a>.</li>
125 <li>No IE 6-10 support. If someone can read code, they are probably in the 95% of the population with a modern browser.</li>
126 </ul>
127 </section>
128
129 <section id="basic-usage" class="language-markup">
130 <h1>Basic usage</h1>
131
132 <p>You will need to include the <code>prism.css</code> and <code>prism.js</code> files you <a href="download.html">downloaded</a> in your page. Example:
133 <pre><code>&lt;!DOCTYPE html>
134 &lt;html>
135 &lt;head>
136 ...
137 <mark>&lt;link href="themes/prism.css" rel="stylesheet" /></mark>
138 &lt;/head>
139 &lt;body>
140 ...
141 <mark>&lt;script src="prism.js">&lt;/script></mark>
142 &lt;/body>
143 &lt;/html></code></pre>
144
145 <p>Prism does its best to encourage good authoring practices. Therefore, it only works with <code>&lt;code></code> elements, since marking up code without a <code>&lt;code></code> element is semantically invalid.
146 <a href="https://www.w3.org/TR/html52/textlevel-semantics.html#the-code-element">According to the HTML5 spec</a>, the recommended way to define a code language is a <code>language-xxxx</code> class, which is what Prism uses.
147 Alternatively, Prism also supports a shorter version: <code>lang-xxxx</code>.</p>
148
149 <p>The <a href="https://www.w3.org/TR/html5/grouping-content.html#the-pre-element">recommended way to mark up a code block</a>
150 (both for semantics and for Prism) is a <code>&lt;pre></code> element with a <code>&lt;code></code> element inside, like so:</p>
151
152 <pre><code>&lt;pre>&lt;code class="language-css">p { color: red }&lt;/code>&lt;/pre></code></pre>
153
154 <p>If you use that pattern, the <code>&lt;pre></code> will automatically get the <code>language-xxxx</code> class (if it doesn’t already have it) and will be styled as a code block.</p>
155
156 <p>Inline code snippets are done like this:</p>
157
158 <pre><code>&lt;code class="language-css">p { color: red }&lt;/code></code></pre>
159
160 <p><strong>Note</strong>: You have to escape all <code>&lt;</code> and <code>&amp;</code> characters inside <code>&lt;code></code> elements (code blocks and inline snippets) with <code>&amp;lt;</code> and <code>&amp;amp;</code> respectively, or else the browser might interpret them as an HTML tag or <a href="https://developer.mozilla.org/en-US/docs/Glossary/Entity">entity</a>. If you have large portions of HTML code, you can use the <a href="plugins/unescaped-markup/">Unescaped Markup plugin</a> to work around this.</p>
161
162 <h3>Language inheritance</h3>
163
164 <p>To make things easier however, Prism assumes that the language class is inherited. Therefore, if multiple <code>&lt;code></code> elements have the same language, you can add the <code>language-xxxx</code> class on one of their common ancestors.
165 This way, you can also define a document-wide default language, by adding a <code>language-xxxx</code> class on the <code>&lt;body></code> or <code>&lt;html></code> element.</p>
166
167 <p>If you want to opt-out of highlighting a <code>&lt;code></code> element that inherits its language, you can add the <code>language-none</code> class to it. The <code>none</code> language can also be inherited to disable highlighting for the element with the class and all of its descendants.</p>
168
169 <p>If you want to opt-out of highlighting but still use plugins like <a href="plugins/show-invisibles/">Show Invisibles</a>, add use <code>language-plain</code> class instead.</p>
170
171 <h3>Manual highlighting</h3>
172
173 <p>If you want to prevent any elements from being automatically highlighted and instead use the <a href="extending.html#api">API</a>, you can set <a href="docs/Prism.html#.manual"><code class="language-javascript">Prism.manual</code></a> to <code class="language-javascript">true</code> before the <code>DOMContentLoaded</code> event is fired. By setting the <code>data-manual</code> attribute on the <code>&lt;script></code> element containing Prism core, this will be done automatically.
174 Example:</p>
175
176 <pre><code>&lt;script src="prism.js" data-manual>&lt;/script></code></pre>
177
178 <p>or</p>
179
180 <pre><code>&lt;script>
181 window.Prism = window.Prism || {};
182 window.Prism.manual = true;
183 &lt;/script>
184 &lt;script src="prism.js">&lt;/script></code></pre>
185
186 <h2 id="basic-usage-cdn">Usage with CDNs</h2>
187
188 <p>In combination with CDNs, we recommend using the <a href="plugins/autoloader">Autoloader plugin</a> which automatically loads languages when necessary.</p>
189
190 <p>The setup of the Autoloader, will look like the following. You can also add your own themes of course.</p>
191
192 <pre><code>&lt;!DOCTYPE html>
193 &lt;html>
194 &lt;head>
195 ...
196 <mark>&lt;link href="https://{{cdn}}/[email protected]/themes/prism.css" rel="stylesheet" /></mark>
197 &lt;/head>
198 &lt;body>
199 ...
200 <mark> &lt;script src="https://{{cdn}}/[email protected]/components/prism-core.min.js"&gt;&lt;/script&gt;
201 &lt;script src="https://{{cdn}}/[email protected]/plugins/autoloader/prism-autoloader.min.js"&gt;&lt;/script&gt;</mark>
202 &lt;/body>
203 &lt;/html></code></pre>
204
205 <p>Please note that links in the above code sample serve as placeholders. You have to replace them with valid links to the CDN of your choice.</p>
206
207 <p>CDNs which provide PrismJS are e.g. <a href="https://cdnjs.com/libraries/prism">cdnjs</a>, <a href="https://www.jsdelivr.com/package/npm/prismjs">jsDelivr</a>, and <a href="https://unpkg.com/browse/prismjs@1/">UNPKG</a>.</p>
208
209 <h2 id="basic-usage-bundlers">Usage with Webpack, Browserify, & Other Bundlers</h2>
210
211 <p>If you want to use Prism with a bundler, install Prism with <code>npm</code>:</p>
212
213 <pre><code>$ npm install prismjs</code></pre>
214
215 <p>You can then <code class="language-js">import</code> into your bundle:</p>
216
217 <pre><code class="language-js">import Prism from 'prismjs';</code></pre>
218
219 <p>To make it easy to configure your Prism instance with only the languages and plugins you need, use the babel plugin,
220 <a href="https://github.com/mAAdhaTTah/babel-plugin-prismjs">babel-plugin-prismjs</a>. This will allow you to load
221 the minimum number of languages and plugins to satisfy your needs.
222 See that plugin's documentation for configuration details.</p>
223
224 <h2 id="basic-usage-node">Usage with Node</h2>
225
226 <p>If you want to use Prism on the server or through the command line, Prism can be used with Node.js as well.
227 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>
228
229 <p>Example:</p>
230 <pre><code class="language-js">const Prism = require('prismjs');
231
232 // The code snippet you want to highlight, as a string
233 const code = `var data = 1;`;
234
235 // Returns a highlighted HTML string
236 const html = Prism.highlight(code, Prism.languages.javascript, 'javascript');</code></pre>
237
238 <p>Requiring <code>prismjs</code> will load the default languages: <code>markup</code>, <code>css</code>,
239 <code>clike</code> and <code>javascript</code>. You can load more languages with the
240 <code class="language-javascript">loadLanguages()</code> utility, which will automatically handle any required dependencies.</p>
241 <p>Example:</p>
242
243 <pre><code class="language-js">const Prism = require('prismjs');
244 const loadLanguages = require('prismjs/components/');
245 loadLanguages(['haml']);
246
247 // The code snippet you want to highlight, as a string
248 const code = `= ['hi', 'there', 'reader!'].join " "`;
249
250 // Returns a highlighted HTML string
251 const html = Prism.highlight(code, Prism.languages.haml, 'haml');</code></pre>
252
253 <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>
254
255 <p><strong>Note</strong>: <code class="language-javascript">loadLanguages()</code> will ignore unknown languages and log warning messages to the console. You can prevent the warnings by setting <code class="language-javascript">loadLanguages.silent = true</code>.</p>
256
257 </section>
258
259 <section class="language-markup">
260 <h1>Supported languages</h1>
261 <p>This is the list of all <span id="languages-list-count"></span> languages currently supported by Prism, with
262 their corresponding alias, to use in place of <code>xxxx</code> in the <code>language-xxxx</code> (or <code>lang-xxxx</code>) class:</p>
263 <div id="languages-list"></div>
264 <p>Couldn’t find the language you were looking for? <a href="https://github.com/PrismJS/prism/issues" target="_blank">Request it</a>!</p>
265 </section>
266
267 <section id="plugins">
268 <h1>Plugins</h1>
269 <p>Plugins are additional scripts (and CSS code) that extend Prism’s functionality. Many of the following plugins are official, but are released as plugins to keep the Prism Core small for those who don’t need the extra functionality.</p>
270 <ul class="plugin-list language-none"></ul>
271
272 <p>No assembly required to use them. Just select them in the <a href="download.html">download</a> page.</p>
273 <p>It’s very easy to <a href="extending.html#writing-plugins">write your own Prism plugins</a>. Did you write a plugin for Prism that you want added to this list? <a href="https://github.com/LeaVerou/prism" target="_blank">Send a pull request</a>!</p>
274 </section>
275
276 <section id="languages">
277 <h1>Third-party language definitions</h1>
278
279 <ul>
280 <li><a href="https://github.com/SassDoc/prism-scss-sassdoc">SassDoc Sass/Scss comments</a></li>
281 <li><a href="https://github.com/Liquibase/prism-liquibase">Liquibase CLI Bash language extension</a></li>
282 </ul>
283 </section>
284
285 <section id="tutorials">
286 <h1>Third-party tutorials</h1>
287
288 <p>Several tutorials have been written by members of the community to help you integrate Prism into multiple different website types and configurations:</p>
289
290 <ul>
291 <li><a href="https://startblogging101.com/how-to-add-prism-js-syntax-highlighting-wordpress/">How to Add Prism.js Syntax Highlighting to Your WordPress Site</a></li>
292 <li><a href="https://websitebeaver.com/escape-html-inside-code-or-pre-tag-to-entities-to-display-raw-code-with-prismjs">Escape HTML Inside &lt;code&gt; or &lt;pre&gt; Tag to Entities to Display Raw Code with PrismJS</a></li>
293 <li><a href="http://wp.tutsplus.com/tutorials/plugins/adding-a-syntax-highlighter-shortcode-using-prism-js/">Adding a Syntax Highlighter Shortcode Using Prism.js | WPTuts+</a></li>
294 <li><a href="https://www.stramaxon.com/2012/07/prism-syntax-highlighter-for-blogger.html">Implement PrismJs Syntax Highlighting to your Blogger/BlogSpot</a></li>
295 <li><a href="https://schier.co/blog/2013/01/07/how-to-re-run-prismjs-on-ajax-content.html">How To Re-Run Prism.js On AJAX Content</a></li>
296 <li><a href="https://www.semisedlak.com/highlight-your-code-syntax-with-prismjs">Highlight your code syntax with Prism.js</a></li>
297 <li><a href="https://usetypo3.com/fs-code-snippet.html">A code snippet content element powered by Prism.js for TYPO3 CMS</a></li>
298 <li><a href="https://auralinna.blog/post/2017/code-syntax-highlighting-with-angular-and-prismjs">Code syntax highlighting with Angular and Prism.js</a></li>
299 <li><a href="https://mkaz.blog/wordpress/code-syntax-highlighting-in-gutenberg/">Code syntax highlighting in Gutenberg, WordPress block editor</a></li>
300 <li><a href="https://karlkaufmann.com/writing/technotes/code-highlighting-prism-drupal">Code Highlighting with Prism.js in Drupal</a></li>
301 <li><a href="https://betterstack.dev/blog/code-highlighting-in-react-using-prismjs/">Code highlighting in React using Prism.js</a></li>
302 <li><a href="https://www.akashmittal.com/react-native-prismjs-using-webview/">Using Prism.js in React Native</a></li>
303 <li><a href="https://itsmycode.com/prismjs-tutorial/">PrismJS Tutorial | Implement Prism in HTML and React</a></li>
304 <li>Code syntax highlighting in Pug with <a href="https://webdiscus.github.io/pug-loader/pug-filters/highlight.html">:highlight</a> and <a href="https://webdiscus.github.io/pug-loader/pug-filters/markdown.html">:markdown</a> filters using <a href="https://github.com/webdiscus/pug-loader">pug-loader</a> and Prism.js</li>
305 </ul>
306
307 <p>Please note that the tutorials listed here are not verified to contain correct information. Read at your risk and always check the official documentation here if something doesn’t work :)</p>
308
309 <p>Have you written a tutorial about Prism that’s not already included here? Send a pull request!</p>
310 </section>
311
312 <section id="credits">
313 <h1>Credits</h1>
314 <ul>
315 <li>Special thanks to <a href="https://github.com/RunDevelopment">Michael Schmidt</a>, <a href="https://github.com/mAAdhaTTah">James DiGioia</a>, <a href="https://github.com/Golmote">Golmote</a> and <a href="https://github.com/apfelbox">Jannik Zschiesche</a> for their contributions and for being <strong>amazing maintainers</strong>. Prism would not have been able to keep up without their help.</li>
316 <li>To <a href="https://twitter.com/kizmarh">Roman Komarov</a> for his contributions, feedback and testing.</li>
317 <li>To <a href="https://twitter.com/zdfs">Zachary Forrest</a> for <a href="https://twitter.com/zdfs/statuses/217834980871639041">coming up with the name “Prism”</a></li>
318 <li>To <a href="https://stellarr.deviantart.com/">stellarr</a> for the <a href="https://stellarr.deviantart.com/art/Spectra-Wallpaper-Pack-97785901">spectrum background</a> used on this page</li>
319 <li>To <a href="https://twitter.com/thecodezombie">Jason Hobbs</a> for <a href="https://twitter.com/thecodezombie/status/217663703825399809">encouraging me</a> to release this script as standalone</li>
320 </ul>
321 </section>
322
323 <footer data-src="assets/templates/footer.html" data-type="text/html"></footer>
324
325 <script src="assets/vendor/utopia.js"></script>
326 <script src="prism.js"></script>
327 <script src="plugins/keep-markup/prism-keep-markup.js"></script>
328 <script src="components.js"></script>
329 <script src="assets/code.js"></script>
330 <script>
331 (function() {
332 var languageItems = [];
333 var languages = components.languages;
334 var count = 0;
335 for (var id in languages) {
336 if (id == 'meta') {
337 continue;
338 }
339 count++;
340
341 var lang = languages[id];
342 var name = lang.title || lang;
343
344 var contents = [
345 name,
346 ' - ',
347 {
348 tag: 'code',
349 contents: id
350 }
351 ];
352
353 var alias = lang.alias;
354 if (typeof alias === 'string')
355 alias = [alias];
356
357 if (alias) {
358 for (var i = 0, l = alias.length; i < l; i++) {
359 contents.push(
360 ', ',
361 {
362 tag: 'code',
363 contents: alias[i]
364 });
365 }
366 }
367
368 languageItems.push({
369 tag: 'li',
370 attributes: {
371 'data-id': id
372 },
373 contents: contents
374 });
375 }
376 $u.element.create('ul', {
377 contents: languageItems,
378 inside: '#languages-list'
379 });
380 $u.element.contents($('#languages-list-count'), count);
381 }());
382 </script>
383
384 </body>
385 </html>