forked from PrismJS/prism
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.html
437 lines (389 loc) · 13.4 KB
/
tokens.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="assets/favicon.png" />
<title>Prism tokens ▲ Prism</title>
<link rel="stylesheet" href="assets/style.css" />
<link rel="stylesheet" href="themes/prism.css" data-noprefix />
<link rel="stylesheet" href="plugins/line-highlight/prism-line-highlight.css" data-noprefix />
<link rel="stylesheet" href="plugins/toolbar/prism-toolbar.css" data-noprefix />
<script src="assets/vendor/prefixfree.min.js"></script>
<script>var _gaq = [['_setAccount', 'UA-33746269-1'], ['_trackPageview']];</script>
<script src="https://www.google-analytics.com/ga.js" async></script>
<style>
table.styled {
border: 1px solid #ccc;
border-spacing: 0;
}
table.styled tr:not(:first-child) > * {
border-top: 1px solid #ccc;
}
table.styled tr > *:not(:first-child) {
border-left: 1px solid #ccc;
}
table.styled tr:nth-child(2n + 1) {
background-color: #F8F8F8;
}
table.styled tr > * {
padding: .5em .75em;
}
table.styled tr > th {
text-align: left;
}
</style>
</head>
<body class="language-none">
<header>
<div class="intro" data-src="assets/templates/header-main.html" data-type="text/html"></div>
<h2>Prism tokens</h2>
<p>Prism identifies tokens in your code, which are in turn styled by CSS to produce the syntax highlighting. This page provides an overview of the standard tokens and corresponding examples.</p>
</header>
<section id="standard-tokens">
<h1>Standard tokens</h1>
<p>When defining a new language, you will need to provide token names for each 'type' of code, such as keywords and operators, so Prism's themes can assign colors (and other styles) accordingly. Prism's themes (both official and non-official) only guarantee coverage for these standard tokens, so it is recommended to make use of the following standard tokens to ensure that code will be highlighted.</p>
<table class="styled">
<tbody>
<tr>
<th colspan="2">General purpose</th>
</tr>
<tr>
<td><code>keyword</code></td>
<td>
Pre-defined and reserved words.
<pre><code class="language-javascript">for (const foo of bar) {
if (foo === 'foobar') break;
await foo;
}</code></pre>
</td>
</tr>
<tr>
<td><code>builtin</code></td>
<td>
Functions/Methods/Classes/Types that are available out of the box.
<pre><code class="language-python">pi = round(float('3.14159'), 2)</code></pre>
<pre><code class="language-typescript">type SearchFunc = (source: string, subStr: string) => boolean;</code></pre>
</td>
</tr>
<tr>
<td><code>class-name</code></td>
<td>
The name of a class, interface, trait, or type.
<pre><code class="language-javascript">class Rectangle extends Square { /* ... */ }</code></pre>
<pre><code class="language-csharp">public class CameraController : MonoBehaviour { /* ... */ }</code></pre>
</td>
</tr>
<tr>
<td><code>function</code></td>
<td>
The name of a function or method.
<pre><code class="language-javascript">function isEven(number) {
return Number(number) % 2 === 0;
}
const isOdd = (number) => !isEven(number);</code></pre>
</td>
</tr>
<tr>
<td><code>boolean</code></td>
<td>
True and false, and pairs with similar concepts (e.g. yes and no).
<pre><code class="language-javascript">console.log(true === false); // prints false
console.log(true === !false); // prints true</code></pre>
</td>
</tr>
<tr>
<td><code>number</code></td>
<td>
A numerical value, regardless of base and order, and no matter real or imaginary.
<pre><code class="language-python">print(3.14159 * 42)
print(1e100 + .001j)
return foo & 0xdeadbeef</code></pre>
</td>
</tr>
<tr>
<td><code>string</code></td>
<td>
Literal text, including numbers and symbols and maybe even more special characters.
<pre><code class="language-javascript">let greeting = 'Hello World!';</code></pre>
</td>
</tr>
<tr>
<td><code>char</code></td>
<td>
A string that can comprise only a single character, enforced by the language.
<pre><code class="language-elm">['A', 'z', '0', '-', '\t', '\u{2728}']</code></pre>
</td>
</tr>
<tr>
<td><code>symbol</code></td>
<td>
A primitive data type found in some languages, can be thought of as an identifier.
<pre><code class="language-smalltalk">#myFirstSymbol "#myFirstSymbol is a symbol in Smalltalk"</code></pre>
</td>
</tr>
<tr>
<td><code>regex</code></td>
<td>
A regular expression.
<pre><code class="language-javascript">let entity = /&#x?[\da-f]{1,8};/;</code></pre>
</td>
</tr>
<tr>
<td><code>url</code></td>
<td>
A link to another page or resource.
<pre><code class="language-css">body {
background: url(foo.png);
}</code></pre>
<pre><code class="language-markdown">[Prism](https://prismjs.com) is a cool syntax highlighter.</code></pre>
</td>
</tr>
<tr>
<td><code>operator</code></td>
<td>
A symbol that represents an action or process, whether it's a mathematical operation, logical operation, and so on.
<pre><code class="language-javascript">x += (y + 4 >> -z === w) ? b ** c : ~a;</code></pre>
</td>
</tr>
<tr>
<td><code>variable</code></td>
<td>
The name of a variable. This token is intended to be used sparingly. It's generally used on special variables (e.g. Less or Bash), not general variables from imperative and procedural programming languages (e.g. C, JavaScript, Python).
<pre><code class="language-less">@nice-blue: #5B83AD;
@light-blue: lighten(@nice-blue, 20%);</code></pre>
<pre><code class="language-bash">echo $STRING
args=("$@")
echo ${args[0]} ${args[1]} ${args[2]}</code></pre>
</td>
</tr>
<tr>
<td><code>constant</code></td>
<td>
The name of a constant.
<pre><code class="language-javascript">const PI = 3.14159;</code></pre>
<pre><code class="language-rust">const THING: u32 = 0xABAD1DEA;</code></pre>
<pre><code class="language-c">fprintf(stdout, "hello world\n");</code></pre>
</td>
</tr>
<tr>
<td><code>property</code></td>
<td>
An attribute/characteristic or object/map key.
<pre><code class="language-css">body {
color: red;
line-height: normal;
}</code></pre>
<pre><code class="language-json">{
"data": { "labels": ["foo", "bar"], },
"error": null,
"status": "Ok"
}</code></pre>
</td>
</tr>
<tr>
<td><code>punctuation</code></td>
<td>
Punctuation such as brackets, parentheses, commas, and more.
<pre><code class="language-python">def median(pool):
copy = sorted(pool)
size = len(copy)
if size % 2 == 1:
return copy[(size - 1) / 2]
else:
return (copy[size/2 - 1] + copy[size/2]) / 2</code></pre>
</td>
</tr>
<tr>
<td><code>important</code></td>
<td>
Anything that is important and needs special highlighting.
<pre><code class="language-css">body {
color: red !important;
}</code></pre>
<pre><code class="language-markdown"># This is a heading. Headings are important.</code></pre>
</td>
</tr>
<tr>
<td><code>comment</code></td>
<td>
Code comments.
<pre><code class="language-markup"><!-- Here's a comment -->
<style>
/* Here's another comment */
</style>
<script>
// Here's yet another comment
</script></code></pre>
</td>
</tr>
<tr>
<th colspan="2">Markup languages</th>
</tr>
<tr>
<td><code>tag</code></td>
<td>
A markup tag (e.g. HTML and XML tags).
<pre><code class="language-markup"><p>Hello World!</p></code></pre>
</td>
</tr>
<tr>
<td><code>attr-name</code>, <code>attr-value</code></td>
<td>
Kind of like a property of a markup tag and its value/argument respectively.
<pre><code class="language-markup"><p id="greeting">Hello World!</p>
<video width="1280" height="720" allowfullscreen controls>
<source src="hello_world.mp4" type="video/mp4" />
</video></code></pre>
</td>
</tr>
<tr>
<td><code>namespace</code></td>
<td>
Used to provide uniquely named elements and attributes in XML documents. Outside of markup languages, it is used to tokenize the package/namespace part of identifiers.
<pre><code class="language-markup"><html:p foo:bar="baz" foo:weee></html:p></code></pre>
<pre><code class="language-java">class Foo extends foo.bar.Foo {
java.util.List<foo.bar.Foo.Bar> bar(foo.bar.Baz bat) {
throw new java.lang.UnsupportedOperationException();
}
}</code></pre>
<pre><code class="language-rust">use std::sync::Arc;</code></pre>
</td>
</tr>
<tr>
<td><code>prolog</code></td>
<td>
The first part of an XML document.
<pre><code class="language-markup"><?xml version="1.0" encoding="utf-8"?>
<svg></svg></code></pre>
</td>
</tr>
<tr>
<td><code>doctype</code></td>
<td>
Document type declaration, specific to markup languages.
<pre><code class="language-markup"><!DOCTYPE html>
<html></html></code></pre>
</td>
</tr>
<tr>
<td><code>cdata</code></td>
<td>
Character data, specific to markup languages.
<pre><code class="language-markup"><ns1:description><![CDATA[
CDATA is <not> magical.
]]></ns1:description></code></pre>
</td>
</tr>
<tr>
<td><code>entity</code></td>
<td>
Code used to display reserved characters in markup languages.
<pre><code class="language-markup">&amp; &#x2665; &#160; &#x152;</code></pre>
</td>
</tr>
<tr>
<th colspan="2">Document-markup languages</th>
</tr>
<tr>
<td><code>bold</code></td>
<td>
Bolded text. Mostly found in document-markup languages.
<pre><code class="language-markdown">**I am bolded text!**</code></pre>
</td>
</tr>
<tr>
<td><code>italic</code></td>
<td>
Italicised text. Mostly found in document-markup languages.
<pre><code class="language-markdown">*I am italicised text!*</code></pre>
</td>
</tr>
<tr>
<th colspan="2">Stylesheets</th>
</tr>
<tr>
<td><code>atrule</code></td>
<td>
Literally <code>@</code> rules (statements) in stylesheets.
<pre><code class="language-css">@font-family {
font-family: Questrial;
src: url(questrial.otf);
}
@media screen and (min-width: 768px) { /* ... */ }</code></pre>
</td>
</tr>
<tr>
<td><code>selector</code></td>
<td>
Code that identifies or picks something out of a group to operate on, such as the names of HTML elements in stylesheets.
<pre><code class="language-css">section h1,
#features li strong,
header h2,
footer p { /* ... */ }</code></pre>
</td>
</tr>
<tr>
<th colspan="2">Diff</th>
</tr>
<tr>
<td><code>inserted</code>, <code>deleted</code></td>
<td>
Added or modified line and deleted line respectively, mainly for diffs. In general, also the idea of something being increased and decreased/removed respectively.
<pre><code class="language-diff">--- bar.yml 2014-12-16 11:43:41 +0800
+++ /Users/foo/Desktop/bar.yml 2014-12-31 11:28:08 +0800
@@ -4,5 +4,5 @@
project:
sources: "src/*.cpp"
headers: "src/*.h"
- qt: core
+ qt: core gui
public_headers: "src/*.h"</code></pre>
</td>
</tr>
</tbody>
</table>
</section>
<section id="embedded-languages">
<h1>Embedded languages</h1>
<p>In addition to the standard tokens above, Prism also has a token for languages that are embedded in another language, such as CSS in HTML, JS in HTML, Bash in Shell-session, and CSS in JS, allowing Prism's themes to highlight the tokens in the embedded languages more accurately. All embedded languages are wrapped in their own special token, which includes a CSS class <code>language-xxxx</code> corresponding to the embedded language.</p>
<p>Open your browser's developer tools and check out the example below to see it in action!</p>
<pre data-line="6-10,14-18"><code class="language-markup"><!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>
</section>
<section id="non-standard-tokens">
<h1>Non-standard tokens</h1>
<p>Sometimes, a language might use a particular name to refer to certain pieces of code, but which is not one of Prism's standard token names, such as <code>function-defintion</code>. Since <code>function-definition</code> is not a standard token, you might want to alias it with a standard token such as <code>function</code>, which is semantically similar, and will ensure that Prism's themes will highlight it. Here's an example:</p>
<pre><code class="language-rust">fn main() {
println!("Hello World");
another_function();
}</code></pre>
</section>
<footer data-src="assets/templates/footer.html" data-type="text/html"></footer>
<script src="assets/vendor/utopia.js"></script>
<script src="prism.js"></script>
<script src="plugins/autoloader/prism-autoloader.js"></script>
<script src="plugins/line-highlight/prism-line-highlight.js"></script>
<script src="plugins/toolbar/prism-toolbar.js"></script>
<script src="plugins/show-language/prism-show-language.js"></script>
<script src="components.js"></script>
<script src="assets/code.js"></script>
</body>
</html>