File tree Expand file tree Collapse file tree
assets/highlighting-tests Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ // Comments
2+ // Single-line comment
3+
4+ /*
5+ * Multi-line
6+ * comment
7+ */
8+
9+ // Numbers
10+ 42 ;
11+ 3.14 ;
12+ .5 ;
13+ 1e10 ;
14+ 1.5e-3 ;
15+ 0xff ;
16+ 0xFF ;
17+ 0b1010 ;
18+ 0o77 ;
19+ 1_000_000 ;
20+ 42n ;
21+
22+ // Constants
23+ true ;
24+ false ;
25+ null ;
26+ undefined ;
27+ NaN ;
28+ Infinity ;
29+
30+ // Strings
31+ 'single quotes with escape: \' \n \t \\' ;
32+ "double quotes with escape: \" \n \t \\" ;
33+
34+ // Control flow keywords
35+ if ( true ) {
36+ } else if ( false ) {
37+ } else {
38+ }
39+
40+ for ( let i = 0 ; i < 10 ; i ++ ) {
41+ if ( i === 5 ) continue ;
42+ if ( i === 8 ) break ;
43+ }
44+
45+ while ( false ) { }
46+ do { } while ( false ) ;
47+
48+ switch ( 42 ) {
49+ case 1 : break ;
50+ default : break ;
51+ }
52+
53+ try {
54+ throw new Error ( "oops" ) ;
55+ } catch ( e ) {
56+ } finally {
57+ }
58+
59+ debugger ;
60+
61+ // Template literals
62+ `template literal: ${ 1 + 2 } and ${ greet ( "world" ) } ` ;
63+ `multi
64+ line
65+ template` ;
66+
67+ // Other keywords (some are contextually reserved)
68+ var a = 1 ;
69+ let b = 2 ;
70+ const c = 3 ;
71+
72+ function greet ( name ) {
73+ return "Hello, " + name ;
74+ }
75+
76+ async function fetchData ( ) {
77+ const result = await fetch ( "/api" ) ;
78+ return result ;
79+ }
80+
81+ function * gen ( ) {
82+ yield 1 ;
83+ yield 2 ;
84+ }
85+
86+ class Animal extends Object {
87+ static count = 0 ;
88+
89+ constructor ( name ) {
90+ super ( ) ;
91+ this . name = name ;
92+ Animal . count ++ ;
93+ }
94+
95+ speak ( ) {
96+ return `${ this . name } speaks` ;
97+ }
98+ }
99+
100+ const obj = { a : 1 } ;
101+ delete obj . a ;
102+ typeof obj ;
103+ void 0 ;
104+ "a" instanceof Object ;
105+ "a" in obj ;
106+
107+ import { readFile } from "fs" ;
108+ export const PI = 3.14 ;
109+ for ( const x of [ 1 , 2 ] ) { }
110+ for ( const k in { a : 1 } ) { }
111+
112+ // Function calls
113+ console . log ( "hello" ) ;
114+ Math . max ( 1 , 2 ) ;
115+ [ 1 , 2 , 3 ] . map ( x => x * 2 ) ;
116+ greet ( "world" ) ;
117+ parseInt ( "42" ) ;
Original file line number Diff line number Diff line change @@ -66,10 +66,21 @@ Reference: ![Logo][logo-ref]
6666echo " Hello, world" | tr a-z A-Z
6767```
6868
69+ ``` javascript
70+ export function greet (name ) {
71+ return ` hello ${ name} ` ;
72+ }
73+ ```
74+
6975``` json
7076{
7177 "name" : " gfm-kitchen-sink" ,
7278 "private" : true ,
7379 "scripts" : { "test" : " echo ok" }
7480}
7581```
82+
83+ ``` python
84+ def greet (name : str ) -> str :
85+ return f " hello { name} "
86+ ```
Original file line number Diff line number Diff line change 1+ # Comments
2+ # Single-line comment
3+
4+ # Numbers
5+ 42
6+ 3.14
7+ .5
8+ 1e10
9+ 1.5e-3
10+ 0xff
11+ 0xFF
12+ 0b1010
13+ 0o77
14+ 1_000_000
15+ 3.14j
16+
17+ # Constants
18+ True
19+ False
20+ None
21+
22+ # Strings
23+ 'single quotes: \' \n \t \\ '
24+ "double quotes: \" \n \t \\ "
25+
26+ # Control flow keywords
27+ if True :
28+ pass
29+ elif False :
30+ pass
31+ else :
32+ pass
33+
34+ for i in range (10 ):
35+ if i == 5 :
36+ continue
37+ if i == 8 :
38+ break
39+
40+ while False :
41+ pass
42+
43+ match 42 :
44+ case 1 :
45+ pass
46+ case _:
47+ pass
48+
49+ try :
50+ raise ValueError ("oops" )
51+ except ValueError as e :
52+ pass
53+ finally :
54+ pass
55+
56+ with open ("/dev/null" ) as f :
57+ pass
58+
59+ return # (only valid inside a function)
60+
61+ # Triple-quoted strings
62+ """
63+ Multi-line
64+ docstring (double quotes)
65+ """
66+
67+ '''
68+ Multi-line
69+ string (single quotes)
70+ '''
71+
72+ # Prefixed strings (f, r, b)
73+ f"f-string: { 1 + 2 } "
74+ r"raw string: \n is literal"
75+ b"byte string"
76+
77+ # Decorators
78+ @staticmethod
79+ def helper ():
80+ pass
81+
82+ @property
83+ def name (self ):
84+ return self ._name
85+
86+ @custom_decorator
87+ def decorated ():
88+ pass
89+
90+ # Other keywords (some are contextually reserved)
91+ import os
92+ from os import path
93+ import sys as system
94+
95+ def greet (name ):
96+ return "Hello, " + name
97+
98+ async def fetch_data ():
99+ result = await some_coroutine ()
100+ return result
101+
102+ class Animal :
103+ count = 0
104+
105+ def __init__ (self , name ):
106+ self .name = name
107+ Animal .count += 1
108+
109+ def speak (self ):
110+ return f"{ self .name } speaks"
111+
112+ class Dog (Animal ):
113+ pass
114+
115+ lambda x : x + 1
116+
117+ x = 1
118+ del x
119+ assert True
120+ not False
121+ True and False
122+ True or False
123+ 1 is 1
124+ 1 is not 2
125+ 1 in [1 , 2 ]
126+
127+ global _g
128+ nonlocal # (only valid inside nested function)
129+
130+ def gen ():
131+ yield 1
132+ yield from [2 , 3 ]
133+
134+ type Alias = int
135+
136+ # Function calls
137+ print ("hello" )
138+ len ([1 , 2 , 3 ])
139+ list (range (10 ))
140+ greet ("world" )
141+ int ("42" )
142+ "hello" .upper ()
You can’t perform that action at this time.
0 commit comments