Debian Codegraph @

tokens.html

raw symbols SCIP
1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4
5 <meta charset="utf-8" />
6 <link rel="icon" href="assets/favicon.png" />
7 <title>Prism tokens ▲ Prism</title>
8 <link rel="stylesheet" href="assets/style.css" />
9 <link rel="stylesheet" href="themes/prism.css" data-noprefix />
10 <link rel="stylesheet" href="plugins/line-highlight/prism-line-highlight.css" data-noprefix />
11 <link rel="stylesheet" href="plugins/toolbar/prism-toolbar.css" data-noprefix />
12 <script src="assets/vendor/prefixfree.min.js"></script>
13
14 <script>var _gaq = [['_setAccount', 'UA-33746269-1'], ['_trackPageview']];</script>
15 <script src="https://www.google-analytics.com/ga.js" async></script>
16 <style>
17 table.styled {
18 border: 1px solid #ccc;
19 border-spacing: 0;
20 }
21 table.styled tr:not(:first-child) > * {
22 border-top: 1px solid #ccc;
23 }
24 table.styled tr > *:not(:first-child) {
25 border-left: 1px solid #ccc;
26 }
27 table.styled tr:nth-child(2n + 1) {
28 background-color: #F8F8F8;
29 }
30 table.styled tr > * {
31 padding: .5em .75em;
32 }
33 table.styled tr > th {
34 text-align: left;
35 }
36 </style>
37 </head>
38 <body class="language-none">
39
40 <header>
41 <div class="intro" data-src="assets/templates/header-main.html" data-type="text/html"></div>
42
43 <h2>Prism tokens</h2>
44 <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>
45 </header>
46
47 <section id="standard-tokens">
48 <h1>Standard tokens</h1>
49
50 <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>
51
52 <table class="styled">
53 <tbody>
54 <tr>
55 <th colspan="2">General purpose</th>
56 </tr>
57 <tr>
58 <td><code>keyword</code></td>
59 <td>
60 Pre-defined and reserved words.
61
62 <pre><code class="language-javascript">for (const foo of bar) {
63 if (foo === 'foobar') break;
64 await foo;
65 }</code></pre>
66 </td>
67 </tr>
68 <tr>
69 <td><code>builtin</code></td>
70 <td>
71 Functions/Methods/Classes/Types that are available out of the box.
72
73 <pre><code class="language-python">pi = round(float('3.14159'), 2)</code></pre>
74 <pre><code class="language-typescript">type SearchFunc = (source: string, subStr: string) => boolean;</code></pre>
75 </td>
76 </tr>
77 <tr>
78 <td><code>class-name</code></td>
79 <td>
80 The name of a class, interface, trait, or type.
81
82 <pre><code class="language-javascript">class Rectangle extends Square { /* ... */ }</code></pre>
83 <pre><code class="language-csharp">public class CameraController : MonoBehaviour { /* ... */ }</code></pre>
84 </td>
85 </tr>
86 <tr>
87 <td><code>function</code></td>
88 <td>
89 The name of a function or method.
90
91 <pre><code class="language-javascript">function isEven(number) {
92 return Number(number) % 2 === 0;
93 }
94 const isOdd = (number) => !isEven(number);</code></pre>
95 </td>
96 </tr>
97 <tr>
98 <td><code>boolean</code></td>
99 <td>
100 True and false, and pairs with similar concepts (e.g. yes and no).
101
102 <pre><code class="language-javascript">console.log(true === false); // prints false
103 console.log(true === !false); // prints true</code></pre>
104 </td>
105 </tr>
106 <tr>
107 <td><code>number</code></td>
108 <td>
109 A numerical value, regardless of base and order, and no matter real or imaginary.
110
111 <pre><code class="language-python">print(3.14159 * 42)
112 print(1e100 + .001j)
113 return foo & 0xdeadbeef</code></pre>
114 </td>
115 </tr>
116 <tr>
117 <td><code>string</code></td>
118 <td>
119 Literal text, including numbers and symbols and maybe even more special characters.
120
121 <pre><code class="language-javascript">let greeting = 'Hello World!';</code></pre>
122 </td>
123 </tr>
124 <tr>
125 <td><code>char</code></td>
126 <td>
127 A string that can comprise only a single character, enforced by the language.
128
129 <pre><code class="language-elm">['A', 'z', '0', '-', '\t', '\u{2728}']</code></pre>
130 </td>
131 </tr>
132 <tr>
133 <td><code>symbol</code></td>
134 <td>
135 A primitive data type found in some languages, can be thought of as an identifier.
136
137 <pre><code class="language-smalltalk">#myFirstSymbol "#myFirstSymbol is a symbol in Smalltalk"</code></pre>
138 </td>
139 </tr>
140 <tr>
141 <td><code>regex</code></td>
142 <td>
143 A regular expression.
144
145 <pre><code class="language-javascript">let entity = /&#x?[\da-f]{1,8};/;</code></pre>
146 </td>
147 </tr>
148 <tr>
149 <td><code>url</code></td>
150 <td>
151 A link to another page or resource.
152
153 <pre><code class="language-css">body {
154 background: url(foo.png);
155 }</code></pre>
156 <pre><code class="language-markdown">[Prism](https://prismjs.com) is a cool syntax highlighter.</code></pre>
157 </td>
158 </tr>
159 <tr>
160 <td><code>operator</code></td>
161 <td>
162 A symbol that represents an action or process, whether it's a mathematical operation, logical operation, and so on.
163
164 <pre><code class="language-javascript">x += (y + 4 >> -z === w) ? b ** c : ~a;</code></pre>
165 </td>
166 </tr>
167 <tr>
168 <td><code>variable</code></td>
169 <td>
170 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).
171
172 <pre><code class="language-less">@nice-blue: #5B83AD;
173 @light-blue: lighten(@nice-blue, 20%);</code></pre>
174 <pre><code class="language-bash">echo $STRING
175 args=("$@")
176 echo ${args[0]} ${args[1]} ${args[2]}</code></pre>
177 </td>
178 </tr>
179 <tr>
180 <td><code>constant</code></td>
181 <td>
182 The name of a constant.
183
184 <pre><code class="language-javascript">const PI = 3.14159;</code></pre>
185 <pre><code class="language-rust">const THING: u32 = 0xABAD1DEA;</code></pre>
186 <pre><code class="language-c">fprintf(stdout, "hello world\n");</code></pre>
187 </td>
188 </tr>
189 <tr>
190 <td><code>property</code></td>
191 <td>
192 An attribute/characteristic or object/map key.
193
194 <pre><code class="language-css">body {
195 color: red;
196 line-height: normal;
197 }</code></pre>
198 <pre><code class="language-json">{
199 "data": { "labels": ["foo", "bar"], },
200 "error": null,
201 "status": "Ok"
202 }</code></pre>
203 </td>
204 </tr>
205 <tr>
206 <td><code>punctuation</code></td>
207 <td>
208 Punctuation such as brackets, parentheses, commas, and more.
209
210 <pre><code class="language-python">def median(pool):
211 copy = sorted(pool)
212 size = len(copy)
213 if size % 2 == 1:
214 return copy[(size - 1) / 2]
215 else:
216 return (copy[size/2 - 1] + copy[size/2]) / 2</code></pre>
217 </td>
218 </tr>
219 <tr>
220 <td><code>important</code></td>
221 <td>
222 Anything that is important and needs special highlighting.
223
224 <pre><code class="language-css">body {
225 color: red !important;
226 }</code></pre>
227 <pre><code class="language-markdown"># This is a heading. Headings are important.</code></pre>
228 </td>
229 </tr>
230 <tr>
231 <td><code>comment</code></td>
232 <td>
233 Code comments.
234
235 <pre><code class="language-markup">&lt;!-- Here's a comment --&gt;
236 &lt;style&gt;
237 /* Here's another comment */
238 &lt;/style&gt;
239 &lt;script&gt;
240 // Here's yet another comment
241 &lt;/script&gt;</code></pre>
242 </td>
243 </tr>
244 <tr>
245 <th colspan="2">Markup languages</th>
246 </tr>
247 <tr>
248 <td><code>tag</code></td>
249 <td>
250 A markup tag (e.g. HTML and XML tags).
251
252 <pre><code class="language-markup">&lt;p&gt;Hello World!&lt;/p&gt;</code></pre>
253 </td>
254 </tr>
255 <tr>
256 <td><code>attr-name</code>, <code>attr-value</code></td>
257 <td>
258 Kind of like a property of a markup tag and its value/argument respectively.
259
260 <pre><code class="language-markup">&lt;p id="greeting"&gt;Hello World!&lt;/p&gt;
261 &lt;video width="1280" height="720" allowfullscreen controls&gt;
262 &lt;source src="hello_world.mp4" type="video/mp4" /&gt;
263 &lt;/video&gt;</code></pre>
264 </td>
265 </tr>
266 <tr>
267 <td><code>namespace</code></td>
268 <td>
269 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.
270
271 <pre><code class="language-markup">&lt;html:p foo:bar="baz" foo:weee&gt;&lt;/html:p&gt;</code></pre>
272 <pre><code class="language-java">class Foo extends foo.bar.Foo {
273 java.util.List&lt;foo.bar.Foo.Bar&gt; bar(foo.bar.Baz bat) {
274 throw new java.lang.UnsupportedOperationException();
275 }
276 }</code></pre>
277 <pre><code class="language-rust">use std::sync::Arc;</code></pre>
278 </td>
279 </tr>
280 <tr>
281 <td><code>prolog</code></td>
282 <td>
283 The first part of an XML document.
284
285 <pre><code class="language-markup">&lt;?xml version="1.0" encoding="utf-8"?&gt;
286 &lt;svg&gt;&lt;/svg&gt;</code></pre>
287 </td>
288 </tr>
289 <tr>
290 <td><code>doctype</code></td>
291 <td>
292 Document type declaration, specific to markup languages.
293
294 <pre><code class="language-markup">&lt;!DOCTYPE html&gt;
295 &lt;html&gt;&lt;/html&gt;</code></pre>
296 </td>
297 </tr>
298 <tr>
299 <td><code>cdata</code></td>
300 <td>
301 Character data, specific to markup languages.
302
303 <pre><code class="language-markup">&lt;ns1:description&gt;&lt;![CDATA[
304 CDATA is &lt;not&gt; magical.
305 ]]>&lt;/ns1:description&gt;</code></pre>
306 </td>
307 </tr>
308 <tr>
309 <td><code>entity</code></td>
310 <td>
311 Code used to display reserved characters in markup languages.
312
313 <pre><code class="language-markup">&amp;amp; &amp;#x2665; &amp;#160; &amp;#x152;</code></pre>
314 </td>
315 </tr>
316 <tr>
317 <th colspan="2">Document-markup languages</th>
318 </tr>
319 <tr>
320 <td><code>bold</code></td>
321 <td>
322 Bolded text. Mostly found in document-markup languages.
323
324 <pre><code class="language-markdown">**I am bolded text!**</code></pre>
325 </td>
326 </tr>
327 <tr>
328 <td><code>italic</code></td>
329 <td>
330 Italicised text. Mostly found in document-markup languages.
331
332 <pre><code class="language-markdown">*I am italicised text!*</code></pre>
333 </td>
334 </tr>
335 <tr>
336 <th colspan="2">Stylesheets</th>
337 </tr>
338 <tr>
339 <td><code>atrule</code></td>
340 <td>
341 Literally <code>@</code> rules (statements) in stylesheets.
342
343 <pre><code class="language-css">@font-family {
344 font-family: Questrial;
345 src: url(questrial.otf);
346 }
347 @media screen and (min-width: 768px) { /* ... */ }</code></pre>
348 </td>
349 </tr>
350 <tr>
351 <td><code>selector</code></td>
352 <td>
353 Code that identifies or picks something out of a group to operate on, such as the names of HTML elements in stylesheets.
354
355 <pre><code class="language-css">section h1,
356 #features li strong,
357 header h2,
358 footer p { /* ... */ }</code></pre>
359 </td>
360 </tr>
361 <tr>
362 <th colspan="2">Diff</th>
363 </tr>
364 <tr>
365 <td><code>inserted</code>, <code>deleted</code></td>
366 <td>
367 Added or modified line and deleted line respectively, mainly for diffs. In general, also the idea of something being increased and decreased/removed respectively.
368
369 <pre><code class="language-diff">--- bar.yml 2014-12-16 11:43:41 +0800
370 +++ /Users/foo/Desktop/bar.yml 2014-12-31 11:28:08 +0800
371 @@ -4,5 +4,5 @@
372 project:
373 sources: "src/*.cpp"
374 headers: "src/*.h"
375 - qt: core
376 + qt: core gui
377 public_headers: "src/*.h"</code></pre>
378 </td>
379 </tr>
380 </tbody>
381 </table>
382 </section>
383
384 <section id="embedded-languages">
385 <h1>Embedded languages</h1>
386
387 <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>
388
389 <p>Open your browser's developer tools and check out the example below to see it in action!</p>
390
391 <pre data-line="6-10,14-18"><code class="language-markup">&lt;!DOCTYPE html&gt;
392 &lt;html lang="en"&gt;
393 &lt;head&gt;
394 &lt;meta charset="utf-8" /&gt;
395 &lt;title>I can haz embedded CSS and JS&lt;/title&gt;
396 &lt;style&gt;
397 @media print {
398 p { color: red !important; }
399 }
400 &lt;/style&gt;
401 &lt;/head&gt;
402 &lt;body&gt;
403 &lt;h1&gt;I can haz embedded CSS and JS&lt;/h1&gt;
404 &lt;script&gt;
405 if (true) {
406 console.log('foo');
407 }
408 &lt;/script&gt;
409
410 &lt;/body&gt;
411 &lt;/html&gt;</code></pre>
412 </section>
413
414 <section id="non-standard-tokens">
415 <h1>Non-standard tokens</h1>
416
417 <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>
418
419 <pre><code class="language-rust">fn main() {
420 println!("Hello World");
421 another_function();
422 }</code></pre>
423 </section>
424
425 <footer data-src="assets/templates/footer.html" data-type="text/html"></footer>
426
427 <script src="assets/vendor/utopia.js"></script>
428 <script src="prism.js"></script>
429 <script src="plugins/autoloader/prism-autoloader.js"></script>
430 <script src="plugins/line-highlight/prism-line-highlight.js"></script>
431 <script src="plugins/toolbar/prism-toolbar.js"></script>
432 <script src="plugins/show-language/prism-show-language.js"></script>
433 <script src="components.js"></script>
434 <script src="assets/code.js"></script>
435
436 </body>
437 </html>