forked from PrismJS/prism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.html
451 lines (357 loc) · 10.9 KB
/
examples.html
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="shortcut icon" href="favicon.png" />
<title>Examples ▲ Prism</title>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="themes/prism.css" data-noprefix />
<script src="prefixfree.min.js"></script>
<script>var _gaq = [['_setAccount', 'UA-33746269-1'], ['_trackPageview']];</script>
<script src="http://www.google-analytics.com/ga.js" async></script>
</head>
<body>
<header>
<div class="intro" data-src="templates/header-main.html" data-type="text/html"></div>
<h2>Examples</h2>
<p>The examples in this page serve a dual purpose: They act as unit tests, making it easy to spot bugs, and at the same time demonstrate what Prism can do, on simple and on edge cases.</p>
</header>
<section class="language-markup">
<h1>Different markup</h1>
<h2>code.language-css</h2>
<code class="language-css">p { color: red; }</code>
<h2>pre.language-css > code</h2>
<pre class="language-css"><code>p { color: red; }</code></pre>
<h2>pre > code.language-css</h2>
<pre><code class="language-css">p { color: red; }</code></pre>
<h2>pre.language-css > code.language-*</h2>
<pre class="language-css"><code class="language-*">p { color: red; }</code></pre>
<h2>code.lang-css</h2>
<code class="lang-css">p { color: red; }</code>
<h2>pre.lang-css > code</h2>
<pre class="lang-css"><code>p { color: red; }</code></pre>
<h2>pre > code</h2>
<p>No language, should inherit .language-markup</p>
<pre><code><p>hi!</p></code></pre>
<h2>code.language-*</h2>
<p>No language, should inherit .language-markup</p>
<code class="language-*"><p>hi!</p></code>
<h2>code.language-none</h2>
<p>Should not be highlighted.</p>
<code class="language-none"><p>hi!</p></code>
</section>
<section class="language-markup">
<h1>Markup</h1>
<h2>Empty tag</h2>
<pre><code><p></p></code></pre>
<h2>Tag that spans multiple lines</h2>
<pre><code><p
>hello!
</p></code></pre>
<h2>Name-attribute pair</h2>
<pre><code><p></p></code></pre>
<h2>Name-attribute pair without quotes</h2>
<pre><code><p class=prism></p></code></pre>
<h2>Attribute without value</h2>
<pre><code><p data-foo></p></code></pre>
<pre><code><p data-foo ></p></code></pre>
<h2>Namespaces</h2>
<pre><code><html:p foo:bar="baz" foo:weee></html:p></code></pre>
<h2>XML prolog</h2>
<pre><code><?xml version="1.0" encoding="utf-8"?>
<svg></svg></code></pre>
<h2>DOCTYPE</h2>
<pre><code><!DOCTYPE html>
<html></html></code></pre>
<h2>CDATA section</h2>
<pre><code><ns1:description><![CDATA[
CDATA is <not> magical.
]]></ns1:description></code></pre>
<h2>Comment</h2>
<pre><code><!-- I'm a comment -->
And i'm not</code></pre>
<h2>Entities</h2>
<pre><code>&amp; &#x2665; &#160; &#x152;</code></pre>
<h2>Embedded JS and CSS</h2>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>I can haz embedded CSS and JS</title>
<style>
@media print {
p { color: red !important; }
}
</style>
</head>
<body>
<h1>I can haz embedded CSS and JS</h1>
<script>
if (true) {
console.log('foo');
}
</script>
</body>
</html></code></pre>
<h2>Invalid HTML</h2>
<pre><code><l </ul></code></pre>
<h2>Multi-line attribute values</h2>
<pre><code><p title="foo
bar
baz"></code></pre>
</section>
<section class="language-css">
<h1>CSS</h1>
<h2>Empty rule</h2>
<pre><code>*{} * {} p {}</code></pre>
<pre><code>ul,
ol {}</code></pre>
<h2>Simple rule</h2>
<pre><code>p { color: red; }</code></pre>
<h2>Important rule</h2>
<pre><code>p { color: red !important; }</code></pre>
<h2>@ rule</h2>
<pre><code>@media screen and (min-width: 100px) {}</code></pre>
<h2>LESS variable</h2>
<pre><code>@main-color: red;
.foo {
background: @main-color;
}</code></pre>
<h2>Comment</h2>
<pre><code>/* Simple comment here */</code></pre>
<h2>String</h2>
<pre><code>content: 'foo';</code></pre>
<h2>URL</h2>
<pre><code>content: url(foo.png);</code></pre>
</section>
<section class="language-javascript">
<h1>JavaScript</h1>
<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"</code></pre>
<pre><code>/* "foo" */</code></pre>
<h2>Strings with slashes</h2>
<pre><code>env.content + '</' + env.tag + '>'</code></pre>
<pre><code>var foo = "/" + "/";</code></pre>
<pre><code>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;</code></pre>
<pre><code>var foo = /a/, bar = 3/4;</code></pre>
</section>
<section class="language-java">
<h1>Java</h1>
<h2>Java Language Keywords</h2>
<pre><code>
abstract continue for new switch
assert default goto package synchronized
boolean do if private this
break double implements protected throw
byte else import public throws
case enum instanceof return transient
catch extends int short try
char final interface static void
class finally long strictfp volatile
const float native super while
</code></pre>
<h2>Operators</h2>
<pre><code>// postfix
expr++ expr--
// unary
++expr --expr +expr -expr ~ !
// multiplicative
* / %
// additive
+ -
// shift
<< >> >>>
// relational
< > <= >= instanceof
// equality
== !=
// bitwise AND
&
// bitwise exclusive OR
^
// bitwise inclusive OR
|
// logical AND
&&
// logical OR
||
// ternary
? :
// assignment
= += -= *= /= %= &= ^= |= <<= >>= >>>=
</code></pre>
<h2>Simple class example</h2>
<pre><code>package com.prismjs;
import java.io.*;
@SuppressWarnings("unchecked")
public class PrismJS {
public static Integer test = 0;
/**
* Javadoc style comment
*
* @param args
*/
public static void main(String[] args) {
// Let's create some variables
int numArgs = args.length;
Integer a = 0x1;
String test = "" + "Hello" + " \"World\"!";
double dvalue = 1.23;
int optest = 0;
optest += 321 - 45 * 1247 / 425 % 123;
/*
* Multiline comment
*/
for (int i = 0; i < numArgs; i++) {
// Simple line comment
System.out.println("Arg value= " + args[i]);
}
do {
System.out.println("Do while ok!");
} while (false);
}
}
</code></pre>
<p>As you can notice String keyword is not highlighted because it's not a Java language keyword (cf. <a href="http://docs.oracle.com/javase/tutorial/java/nutsandbolts/_keywords.html">Java Language Keywords</a>). The main reason is that String is not a primitive type such as <em>int</em> but a class type like <em>Integer</em>.</p>
</section>
<section class="language-coffeescript">
<h1>Coffeescript</h1>
<h2>Variable assignment</h2>
<pre><code>foo = "bar"</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>Single line comments</h2>
<pre><code># This is a comment</code></pre>
<h2>Link in comment</h2>
<pre><code># http://lea.verou.me
###
Block Comment
### </code></pre>
<h2>Nested strings</h2>
<pre><code>var foo = "foo", bar = "He \"said\" 'hi'!"</code></pre>
<h2>String inside comment</h2>
<pre><code># "foo"</code></pre>
<h2>Strings with slashes</h2>
<pre><code>env.content + '</' + env.tag + '>'</code></pre>
<pre><code>var foo = "/" + "/";</code></pre>
<h2>Two or more division operators on the same line</h2>
<pre><code>foo = 5 / 6 / 7;</code></pre>
<h2>A division operator on the same line as a regex</h2>
<pre><code>foo = 1/2, bar = /a/g;</code></pre>
<pre><code>foo = /a/, bar = 3/4;</code></pre>
<h2>A function</h2>
<pre><code>
_buttonClick: (a, b) ->
@hide()
</code></pre>
<h2>An Object</h2>
<pre><code>
code = {
css: "Cascading Style Sheets"
cs: "CoffeeScript"
}
</code></pre>
<h2>Class Definition</h2>
<pre><code>
class CoffeeScript extends Prism.Javascript
</code></pre>
</section>
<section class="language-http">
<h1>HTTP</h1>
<h2>Request Examples</h2>
<p>A simple HTTP GET request:</p>
<pre><code>GET https://example.tld/v1/:serviceName/users.json?sort=:sortMethod HTTP/1.1</code></pre>
<p>Here is an HTTP POST with a body:</p>
<pre><code>POST https://example.tld/v1/:serviceName/users.json HTTP/1.1
Content-Type: application/json
{
"names": ["test1", "test2"],
"version": 1.0
}
</code></pre>
<h2>Response Examples</h2>
<p>JSON response body:</p>
<pre><code>HTTP/1.1 200 OK
Content-Type: application/json
X-Response-Time: 6ms
{
"users": [
{
"name": "John",
"points": 24
},
{
"name": "Lea",
"points": 15
}
]
}
</code></pre>
<p>XML response body:</p>
<pre><code>HTTP/1.1 200 OK
Content-Type: application/xml
X-Response-Time: 10ms
<root>
<status code="0">
Successful
</status>
</root>
</code></pre>
</section>
<section id="failures" class="language-javascript">
<h1>Known failures (JavaScript)</h1>
<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>
<h2>Comment-like substrings</h2>
<pre><code>"foo /* bar */ baz"; "foo // bar";</code></pre>
<h2>Two quotes of the same type (i.e. both single or both double) inside a regex</h2>
<pre><code>foo = /"foo"/;</code></pre>
</section>
<footer data-src="templates/footer.html" data-type="text/html"></footer>
<script src="prism.js"></script>
<script src="components/prism-java.js"></script>
<script src="components/prism-http.js"></script>
<script src="components/prism-coffeescript.js"></script>
<script src="utopia.js"></script>
<script src="components.js"></script>
<script src="code.js"></script>
</body>
</html>