Hash :
a7064dd4
Author :
Date :
2015-06-20T20:07:37
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
<h1>JavaScript</h1>
<p>To use this language, use the class "language-javascript".</p>
<h2>Variable assignment</h2>
<pre><code>var foo = "bar", baz = 5;</code></pre>
<h2>Operators</h2>
<pre><code>(1 + 2 * 3)/4 >= 3 && 4 < 5 || 6 > 7</code></pre>
<h2>Indented code</h2>
<pre><code>if (true) {
while (true) {
doSomething();
}
}</code></pre>
<h2>Regex with slashes</h2>
<pre><code>var foo = /([^/])\/(\\?.|\[.+?])+?\/[gim]{0,3}/g;</code></pre>
<h2>Regex that ends with double slash</h2>
<pre><code>var bar = /\/\*[\w\W]*?\*\//g;</code></pre>
<h2>Single line comments & regexes</h2>
<pre><code>// http://lea.verou.me
var comment = /\/\*[\w\W]*?\*\//g;</code></pre>
<h2>Link in comment</h2>
<pre><code>// http://lea.verou.me
/* http://lea.verou.me */</code></pre>
<h2>Nested strings</h2>
<pre><code>var foo = "foo", bar = "He \"said\" 'hi'!"</code></pre>
<h2>Strings inside comments</h2>
<pre><code>// "foo"
/* "foo" */</code></pre>
<h2>Strings with slashes</h2>
<pre><code>env.content + '</' + env.tag + '>'
var foo = "/" + "/";
var foo = "http://prismjs.com"; // Strings are strings and comments are comments ;)</code></pre>
<h2>Regex inside single line comment</h2>
<pre><code>// hey, /this doesn’t fail!/ :D</code></pre>
<h2>Two or more division operators on the same line</h2>
<pre><code>var foo = 5 / 6 / 7;</code></pre>
<h2>A division operator on the same line as a regex</h2>
<pre><code>var foo = 1/2, bar = /a/g;
var foo = /a/, bar = 3/4;</code></pre>
<h2>ES6 features</h2>
<pre><code>// Regex "y" and "u" flags
/[a-zA-Z]+/gimyu
// for..of loops
for(let x of y) { }
// Modules: import
import { foo as bar } from "file.js"
// Template strings
`Only on ${y} one line`
`This template string ${x} is on
multiple lines.`
`40 + 2 = ${ 40 + 2 }`
`The squares of the first 3 natural integers are ${[for (x of [1,2,3]) x*x].join(', ')}`</code></pre>
<h2>Known failures</h2>
<p>There are certain edge cases where Prism will fail.
There are always such cases in every regex-based syntax highlighter.
However, Prism dares to be open and honest about them.
If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
</p>
<h3>Comment-like substrings</h3>
<pre><code>"foo /* bar */ baz"; "foo // bar";</code></pre>
<h3>Two quotes of the same type (i.e. both single or both double) inside a regex</h3>
<pre><code>foo = /"foo"/;</code></pre>
<h3>Two quotes of the same type (i.e. both single or both double) inside string interpolation</h3>
<pre><code>foo = `${"foo"}`;</code></pre>
<h3>String interpolation containing a closing brace</h3>
<pre><code>`${ {foo:'bar'}.foo }`
`${ '}' }`</code></pre>
<h3>String interpolation containing an unescaped back-tick</h3>
<pre><code>`${ '`' }`</code></pre>