Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
1964 lines (1757 loc) · 85.5 KB
/
Copy pathindex.html
File metadata and controls
1964 lines (1757 loc) · 85.5 KB
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>codelight.js</title>
<meta name="description" content="Syntax highlighting that keeps up with live code. Each line highlighted once, no flicker, no dependencies. 50+ languages, 16 KB.">
<link rel="canonical" href="https://codelightjs.github.io/">
<meta property="og:type" content="website">
<meta property="og:site_name" content="codelight.js">
<meta property="og:title" content="codelight.js: syntax highlighting that keeps up with live code">
<meta property="og:description" content="Very fast and lightweight. Each line highlighted once, no flicker, no dependencies. 50+ languages, 16 KB.">
<meta property="og:url" content="https://codelightjs.github.io/">
<meta property="og:image" content="https://codelightjs.github.io/og.png">
<meta property="og:image:width" content="1280">
<meta property="og:image:height" content="640">
<meta property="og:image:alt" content="codelight.js: syntax highlighting that keeps up with live code">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="codelight.js: syntax highlighting that keeps up with live code">
<meta name="twitter:description" content="Very fast and lightweight. Each line highlighted once, no flicker, no dependencies. 50+ languages, 16 KB.">
<meta name="twitter:image" content="https://codelightjs.github.io/og.png">
<link rel="alternate" type="text/plain" href="llms.txt" title="codelight.js for AI assistants">
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Crect width='32' height='32' rx='7' fill='%2311141a'/%3E%3Cpath d='M9 11l-4 5 4 5M23 11l4 5-4 5' stroke='%23ff7aa8' stroke-width='2.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3Ccircle cx='16' cy='16' r='3.4' fill='%23ffb86b'/%3E%3C/svg%3E">
<link rel="stylesheet" href="styles/default.min.css">
<!-- highlight.js, only for the side-by-side comparison -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.11.1/styles/github.min.css" media="(prefers-color-scheme: light)">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@11.11.1/styles/github-dark.min.css" media="(prefers-color-scheme: dark)">
<link rel="stylesheet" href="site.css">
<style>
/* Page-specific styles. Colours, header and footer are in site.css. */
.hero{padding:28px 0 18px;text-align:center}
h1{font-size:clamp(28px,4.4vw,42px);line-height:1.15;margin:0 0 12px;letter-spacing:-.02em}
h1 span{color:var(--accent);white-space:nowrap}
.lead{font-size:18px;color:var(--muted);max-width:680px;margin:0}
.hero .lead{margin:0 auto;max-width:820px;text-wrap:balance}
.hero h1{text-wrap:balance}
.hero{padding:36px 0 8px}
.news{display:inline-flex;align-items:center;gap:8px;margin:0 0 18px;padding:4px 12px 4px 4px;border:1px solid var(--border);border-radius:999px;font-size:13.5px;color:var(--muted);text-decoration:none;background:var(--surface)}
.news:hover{border-color:var(--muted);color:var(--text)}
.news b{background:var(--accent);color:#fff;border-radius:999px;padding:2px 9px;font-weight:600;font-size:12.5px;white-space:nowrap}
.news-short{display:none}
@media (max-width:560px){.news-long{display:none}.news-short{display:inline}}
.cta{display:flex;flex-wrap:wrap;justify-content:center;align-items:center;gap:10px;margin:24px 0 0}
.cta .btn{padding:9px 16px;font-size:15px}
.install{display:inline-flex;align-items:center;border:1px solid var(--border);border-radius:8px;background:var(--surface);overflow:hidden}
.install code{font:14px/1 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;padding:11px 14px}
.install code::before{content:"$ ";color:var(--muted)}
.install button{font:inherit;font-size:13px;border:0;border-left:1px solid var(--border);background:transparent;color:var(--text);padding:11px 13px;cursor:pointer;min-width:74px}
.install button:hover{background:var(--bg)}
.facts{list-style:none;padding:0;margin:28px auto 0;display:grid;grid-template-columns:repeat(4,minmax(0,1fr));max-width:860px;border:1px solid var(--border);border-radius:var(--radius);overflow:hidden;background:var(--border);gap:1px}
.facts li{background:var(--surface)}
.facts a{display:block;padding:14px 12px;text-decoration:none;color:var(--text);height:100%}
.facts a:hover{background:var(--bg)}
.facts b{display:block;font-size:26px;line-height:1.1;letter-spacing:-.02em;color:var(--accent);font-variant-numeric:tabular-nums}
.facts span{display:block;font-size:13px;color:var(--muted);margin-top:4px;line-height:1.35}
.badges{display:flex;flex-wrap:wrap;justify-content:center;gap:6px;margin:18px 0 0}
.badges a{display:inline-flex;line-height:0}
.badges img{height:20px;width:auto}
@media (max-width:720px){.facts{grid-template-columns:repeat(2,minmax(0,1fr))}.news{font-size:12.5px}}
.chat{border:1px solid var(--border);border-radius:var(--radius);background:var(--surface);overflow:hidden;margin-top:26px}
.bar{display:flex;flex-wrap:wrap;align-items:center;gap:8px;padding:10px 12px;border-bottom:1px solid var(--border)}
.bar label{font-size:13px;color:var(--muted);display:flex;align-items:center;gap:6px}
select,input[type=range]{font:inherit;font-size:14px}
select{border:1px solid var(--border);background:var(--bg);color:var(--text);border-radius:6px;padding:4px 6px}
.spacer{flex:1}
.messages{padding:18px;height:560px;overflow-y:auto;overscroll-behavior:contain;background:var(--bg)}
.msg{max-width:100%;margin-bottom:14px}
.msg.user{margin-left:auto;width:fit-content;max-width:80%;background:var(--user);padding:10px 14px;border-radius:14px 14px 4px 14px}
.msg.bot p{margin:0 0 10px}
.msg.bot ul{margin:0 0 10px;padding-left:22px}
.msg.bot :not(pre)>code{background:var(--surface);border:1px solid var(--border);border-radius:5px;padding:1px 5px;font-size:.9em}
.block{border:1px solid var(--border);border-radius:10px;overflow:hidden;margin:0 0 12px}
.block-head{display:flex;justify-content:space-between;align-items:center;font-size:12px;color:var(--muted);padding:6px 12px;border-bottom:1px solid var(--border);background:var(--surface)}
.block pre{margin:0;font:13.5px/1.6 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
.block pre code.cl{padding:12px 14px;min-height:46px}
.caret{display:inline-block;width:8px;height:1.05em;vertical-align:-2px;background:var(--accent);animation:blink 1s steps(1) infinite;margin-left:1px}
@keyframes blink{50%{opacity:0}}
.stats{display:grid;grid-template-columns:repeat(3,1fr);gap:1px;background:var(--border);border-top:1px solid var(--border)}
.stat{background:var(--surface);padding:12px 14px}
.stat b{display:block;font-size:22px;font-variant-numeric:tabular-nums}
.stat small{color:var(--muted);font-size:12.5px}
.stat.win b{color:var(--good)}
section{padding:34px 0 0}
h2{font-size:22px;margin:0 0 12px}
.grid{display:grid;grid-template-columns:minmax(0,1fr);gap:16px}
.card{min-width:0;border:1px solid var(--border);border-radius:var(--radius);background:var(--surface);padding:16px}
.card h3{margin:0 0 6px;font-size:16px}
.card p{margin:0;color:var(--muted);font-size:14.5px}
.snippet{margin:10px 0 0;border:1px solid var(--border);border-radius:10px;overflow:auto}
.snippet pre{margin:0;font:13px/1.6 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
.snippet pre code.cl{padding:12px 14px}
.tabs{display:flex;flex-wrap:wrap;gap:6px;margin:4px 0 0;border-bottom:1px solid var(--border)}
.tabs button{font:inherit;font-size:14.5px;border:1px solid transparent;border-bottom:0;background:none;color:var(--muted);padding:9px 14px;border-radius:8px 8px 0 0;cursor:pointer;margin-bottom:-1px}
.tabs button:hover{color:var(--text)}
.tabs button[aria-selected="true"]{background:var(--surface);border-color:var(--border);color:var(--text);font-weight:600;box-shadow:inset 0 2px 0 var(--accent)}
.panel{border:1px solid var(--border);border-top:0;border-radius:0 0 var(--radius) var(--radius);background:var(--surface);padding:6px 18px 18px}
.panel h3{font-size:16px;margin:18px 0 8px}
.panel p{margin:8px 0;color:var(--muted);font-size:15px}
.panel :not(pre)>code,.notes code,.section-lead code{background:var(--bg);border:1px solid var(--border);border-radius:5px;padding:1px 5px;font-size:.88em}
.notes{margin:16px 0 0;padding:0 0 0 18px;display:grid;gap:8px;color:var(--muted);font-size:14.5px}
.notes b{color:var(--text);font-weight:600}
.notes li,.panel p{min-width:0;overflow-wrap:anywhere}
.langs-title{font-size:20px;margin:34px 0 6px}
.lang-search{display:flex;flex-direction:column;gap:6px;max-width:420px;margin:4px 0 14px;font-size:14px;color:var(--muted)}
.lang-search input{font:inherit;font-size:16px;padding:9px 12px;border:1px solid var(--border);border-radius:8px;background:var(--bg);color:var(--text)}
.lang-list{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:1px;background:var(--border);border:1px solid var(--border);border-radius:var(--radius);overflow:hidden}
.lang-list li{background:var(--surface);padding:9px 12px;font-size:14px;line-height:1.4}
.lang-list b{font-weight:600}
.lang-list span{display:block;color:var(--muted);font:12.5px/1.45 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;overflow-wrap:anywhere}
.lang-none{margin-top:10px;color:var(--muted)}
.try{display:flex;flex-wrap:wrap;align-items:center;gap:10px 14px;margin:18px 0 4px}
.try span{color:var(--muted);font-size:14px}
@media (max-width:900px){.lang-list{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media (max-width:560px){.lang-list{grid-template-columns:minmax(0,1fr)}.tabs button{padding:8px 10px;font-size:13.5px}.panel{padding:4px 12px 14px}}
.section-lead{color:var(--muted);margin:-4px 0 14px}
.langs{display:flex;flex-wrap:wrap;gap:6px;margin:0 0 12px}
.langs button{border:1px solid var(--border);border-radius:999px;padding:4px 11px;font:inherit;font-size:13px;background:var(--surface);color:var(--text);cursor:pointer}
.langs button:hover{border-color:var(--muted)}
.langs button[aria-pressed="true"]{background:var(--accent);border-color:var(--accent);color:#fff}
.example{border:1px solid var(--border);border-radius:var(--radius);overflow:hidden;background:var(--surface)}
.example pre{margin:0;font:13.5px/1.6 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
.example pre code.cl{padding:14px 16px;min-height:330px}
.example textarea{display:none}
/* Long lines wrap, so code never scrolls sideways. The chat and side-by-side panes scroll up and down. */
.wrap pre,.wrap pre code{white-space:pre-wrap;overflow-wrap:anywhere;overflow:visible}
.vs-bar{display:flex;flex-wrap:wrap;gap:10px 18px;align-items:center;margin:0 0 12px}
.vs-bar label{font-size:14px;color:var(--muted);display:flex;gap:8px;align-items:center}
.vs{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}
.vs-pane{border:1px solid var(--border);border-radius:var(--radius);overflow:hidden;background:var(--surface);display:flex;flex-direction:column}
.vs-head{display:flex;justify-content:space-between;gap:10px;padding:9px 14px;border-bottom:1px solid var(--border);font-size:14px}
.vs-head span{color:var(--muted);font-size:13px}
.vs-code{margin:0;font:12.5px/1.55 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace}
.wrap .vs-code{height:340px;overflow-y:auto;overscroll-behavior:contain}
.vs-code code{display:block;min-height:100%;padding:12px 14px !important;overflow:visible}
.vs-stats{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));margin:0;border-top:1px solid var(--border)}
.vs-stats div{padding:10px 14px}
.vs-stats div+div{border-left:1px solid var(--border)}
.vs-stats dt{font-size:12px;color:var(--muted)}
.vs-stats dd{margin:2px 0 0;font-size:20px;font-weight:600;font-variant-numeric:tabular-nums;white-space:nowrap}
.vs-pane:last-child dd{color:var(--good)}
.vs-note{color:var(--muted);font-size:13.5px;margin:10px 0 0}
.detect-try{display:grid;gap:10px;margin:8px 0 6px}
.detect-label{font-size:13px;color:var(--muted)}
.detect-try textarea{width:100%;min-height:150px;resize:vertical;font:13px/1.55 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;padding:12px 14px;border:1px solid var(--border);border-radius:10px;background:var(--bg);color:var(--text);tab-size:4}
.detect-result{font-size:15px}
.detect-result span{color:var(--muted)}
.detect-result b{color:var(--accent)}
.detect-result small{color:var(--muted);margin-left:4px}
.detect-try .snippet{margin:0}
.detect-try .snippet code.cl{min-height:44px}
.detect-samples{display:flex;flex-wrap:wrap;gap:6px}
.detect-samples button{border:1px solid var(--border);border-radius:999px;padding:4px 11px;font:inherit;font-size:13px;background:var(--bg);color:var(--text);cursor:pointer}
.detect-samples button:hover{border-color:var(--muted)}
.options{display:flex;flex-wrap:wrap;gap:6px 18px;margin:0 0 12px;font-size:14px;color:var(--muted)}
.options label{display:inline-flex;align-items:center;gap:6px;cursor:pointer}
.options input{accent-color:var(--accent);width:16px;height:16px}
@media (max-width:720px){
.grid{grid-template-columns:minmax(0,1fr)}
.vs{grid-template-columns:minmax(0,1fr)}
.wrap .vs-code{height:240px}
.messages{height:460px}
.example pre code.cl{min-height:0}
.stats{grid-template-columns:1fr}
.msg.user{max-width:92%}
.messages{padding:12px;min-height:380px}
}
</style>
</head>
<body data-page="home">
<!--HEADER:START (from partials/header.html by tools/build-demo.mjs)-->
<a class="skip" href="#main">Skip to content</a>
<header class="site-header">
<div class="wrap">
<a class="brand" href="./" aria-label="codelight.js home">
<svg width="30" height="30" viewBox="0 0 32 32" aria-hidden="true"><rect width="32" height="32" rx="7" fill="#11141a"/><path d="M9 11l-4 5 4 5M23 11l4 5-4 5" stroke="#ff7aa8" stroke-width="2.6" fill="none" stroke-linecap="round" stroke-linejoin="round"/><circle cx="16" cy="16" r="3.4" fill="#ffb86b"/></svg>
<span>codelight<b>.js</b></span>
<span class="version">v1.6.1</span>
</a>
<nav class="site-nav" id="site-nav" aria-label="Main">
<a href="./#use" data-page="start">Get started</a>
<a href="./#supported-languages" data-page="languages">Languages</a>
<a href="compare.html" data-page="compare">Compare</a>
<a href="benchmark.html" data-page="benchmark">Benchmark</a>
<a href="https://github.com/codelightjs/codelight.js/tree/main/docs">Docs</a>
<a href="about.html" data-page="about">About</a>
</nav>
<div class="header-actions">
<button class="icon-btn" id="theme" type="button" aria-label="Switch theme">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 3a9 9 0 0 1 0 18z" fill="currentColor"/></svg>
</button>
<a class="btn primary gh" href="https://github.com/codelightjs/codelight.js">
<svg viewBox="0 0 16 16" fill="currentColor" aria-hidden="true"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38v-1.33c-2.23.48-2.7-1.07-2.7-1.07-.36-.92-.89-1.17-.89-1.17-.73-.5.06-.49.06-.49.8.06 1.23.83 1.23.83.72 1.22 1.87.87 2.33.66.07-.52.28-.87.5-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82a7.6 7.6 0 0 1 4 0c1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48v2.2c0 .21.15.46.55.38A8 8 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>
<span>GitHub</span>
</a>
<button class="icon-btn menu-btn" id="menu" type="button" aria-label="Menu" aria-expanded="false" aria-controls="site-nav">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true"><path d="M4 7h16M4 12h16M4 17h16"/></svg>
</button>
</div>
</div>
</header>
<!--HEADER:END-->
<main id="main" class="wrap">
<div class="hero">
<a class="news" href="#detect"><b>New in 1.6</b> <span class="news-long">Automatic language detection, plain text when unsure</span><span class="news-short">Language detection</span> <span aria-hidden="true">→</span></a>
<h1>Syntax highlighting that keeps up with <span>live code</span>.</h1>
<p class="lead">Very fast and lightweight. Each line is highlighted once, and only the line being written gets updated, so it stays fast even when the code is long. No flicker, no dependencies.</p>
<div class="cta">
<div class="install"><code>npm i codelight.js</code><button type="button" id="copy-install" aria-label="Copy the install command">Copy</button></div>
<a class="btn primary" href="#try">See it stream ↓</a>
<a class="btn" href="https://github.com/codelightjs/codelight.js/blob/main/docs/README.md">Docs</a>
</div>
<ul class="facts">
<li><a href="https://github.com/codelightjs/codelight.js/blob/main/docs/benchmark.md"><b>4.4×</b><span>faster than highlight.js on live code</span></a></li>
<li><a href="https://github.com/codelightjs/codelight.js/blob/main/SUPPORTED_LANGUAGES.md"><b>50+</b><span>languages, all in one file</span></a></li>
<li><a href="https://www.npmjs.com/package/codelight.js?activeTab=code"><b>16 KB</b><span>gzipped, with zero dependencies</span></a></li>
<li><a href="https://github.com/codelightjs/codelight.js/blob/main/docs/themes.md"><b>AA</b><span>contrast in light and dark themes</span></a></li>
</ul>
<div class="badges" aria-label="Project status">
<a href="https://www.npmjs.com/package/codelight.js"><img src="https://img.shields.io/npm/v/codelight.js?label=npm&color=cb3837" alt="npm version" height="20"></a>
<a href="https://github.com/codelightjs/codelight.js/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/codelightjs/codelight.js/ci.yml?branch=main&label=tests" alt="Tests" height="20"></a>
<a href="https://www.npmjs.com/package/codelight.js#provenance"><img src="https://img.shields.io/badge/npm%20provenance-signed-2ea44f" alt="npm provenance: signed" height="20"></a>
<a href="https://www.npmjs.com/package/codelight.js?activeTab=dependencies"><img src="https://img.shields.io/badge/dependencies-0-2ea44f" alt="Zero dependencies" height="20"></a>
<a href="https://www.npmjs.com/package/codelight.js"><img src="https://img.shields.io/npm/types/codelight.js" alt="TypeScript types included" height="20"></a>
<a href="https://github.com/codelightjs/codelight.js/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/codelight.js" alt="MIT licence" height="20"></a>
</div>
</div>
<div class="chat" id="try">
<div class="bar">
<label>Reply
<select id="reply">
<option value="ts">TypeScript: retry a fetch</option>
<option value="py">Python: parse a CSV</option>
<option value="deploy">Bash + YAML: deploy</option>
<option value="web">HTML + CSS: a card</option>
</select>
</label>
<label>Speed
<input id="speed" type="range" min="1" max="10" value="5">
</label>
<span class="spacer"></span>
<button class="btn primary" id="play" type="button">▶ Replay</button>
</div>
<div class="messages" id="messages" aria-live="polite"></div>
<div class="stats">
<div class="stat win"><b id="s-cl">0</b><small>lines highlighted by codelight.js</small></div>
<div class="stat"><b id="s-naive">0</b><small>lines if every update re-highlighted the whole block</small></div>
<div class="stat"><b id="s-x">–</b><small>less work, and finished lines never change</small></div>
</div>
</div>
<section id="side-by-side">
<h2>Side by side</h2>
<p class="section-lead">The same TypeScript file arrives four characters at a time into both panes. On the left, highlight.js highlights the whole file again on every update, the usual approach. On the right, codelight.js highlights each line once. Try selecting a line in each while it runs.</p>
<div class="vs-bar">
<button class="btn primary" id="vs-run" type="button">▶ Run both</button>
<label>Speed <select id="vs-speed"><option value="1">1 chunk per frame</option><option value="4" selected>4 chunks per frame</option><option value="12">12 chunks per frame</option></select></label>
</div>
<div class="vs">
<div class="vs-pane">
<div class="vs-head"><b>highlight.js</b><span>re-highlights everything</span></div>
<pre class="vs-code"><code class="hljs" id="vs-left"></code></pre>
<dl class="vs-stats"><div><dt>Last update</dt><dd id="l-last">–</dd></div><div><dt>Slowest</dt><dd id="l-max">–</dd></div><div><dt>Elements thrown away</dt><dd id="l-gone">–</dd></div></dl>
</div>
<div class="vs-pane">
<div class="vs-head"><b>codelight.js</b><span>highlights each line once</span></div>
<pre class="vs-code"><code id="vs-right"></code></pre>
<dl class="vs-stats"><div><dt>Last update</dt><dd id="r-last">–</dd></div><div><dt>Slowest</dt><dd id="r-max">–</dd></div><div><dt>Elements thrown away</dt><dd id="r-gone">–</dd></div></dl>
</div>
</div>
<p class="vs-note">Times include updating the page in your browser. They grow on the left as the file gets longer, and stay flat on the right.</p>
<textarea id="vs-source" hidden>import { createHash } from "node:crypto";
/** One cached response, with when it expires. */
interface Entry<T> {
value: T;
expires: number;
etag: string;
}
export interface CacheOptions {
/** How long an entry stays fresh, in milliseconds. */
ttl?: number;
/** The most entries to keep; the oldest are dropped first. */
max?: number;
/** Called when an entry is dropped. */
onEvict?: (key: string) => void;
}
/**
* A small in-memory cache for API responses, with expiry, size limits and ETags.
* Not shared between processes: use Redis for that.
*/
export class ResponseCache<T = unknown> {
private readonly entries = new Map<string, Entry<T>>();
private hits = 0;
private misses = 0;
constructor(private readonly options: CacheOptions = {}) {}
get size(): number {
return this.entries.size;
}
/** The cached value, or undefined if it's missing or stale. */
get(key: string): T | undefined {
const entry = this.entries.get(key);
if (!entry || entry.expires < Date.now()) {
this.misses++;
if (entry) this.delete(key);
return undefined;
}
// Move to the end so the least recently used entry is first.
this.entries.delete(key);
this.entries.set(key, entry);
this.hits++;
return entry.value;
}
set(key: string, value: T, ttl = this.options.ttl ?? 60_000): string {
const etag = createHash("sha1").update(JSON.stringify(value)).digest("hex").slice(0, 16);
this.entries.delete(key);
this.entries.set(key, { value, expires: Date.now() + ttl, etag });
const max = this.options.max ?? 1_000;
while (this.entries.size > max) {
const oldest = this.entries.keys().next().value as string;
this.delete(oldest);
}
return etag;
}
delete(key: string): boolean {
const removed = this.entries.delete(key);
if (removed) this.options.onEvict?.(key);
return removed;
}
/** True if the client's copy (from If-None-Match) is still current. */
isFresh(key: string, ifNoneMatch?: string | null): boolean {
const entry = this.entries.get(key);
return !!entry && !!ifNoneMatch && entry.etag === ifNoneMatch.replace(/^W\//, "").replace(/"/g, "");
}
stats() {
const total = this.hits + this.misses;
return {
size: this.entries.size,
hitRate: total ? Math.round((this.hits / total) * 100) : 0,
hits: this.hits,
misses: this.misses,
};
}
}
/** Wraps a fetch-style handler so repeat requests are served from the cache. */
export function cached<T>(
cache: ResponseCache<T>,
load: (url: URL) => Promise<T>,
): (request: Request) => Promise<Response> {
return async (request) => {
const url = new URL(request.url);
const key = `${request.method} ${url.pathname}${url.search}`;
if (cache.isFresh(key, request.headers.get("if-none-match"))) {
return new Response(null, { status: 304 });
}
let value = cache.get(key);
if (value === undefined) {
try {
value = await load(url);
} catch (err) {
console.error(`Failed to load ${url.pathname}:`, err);
return Response.json({ error: "Upstream error" }, { status: 502 });
}
}
const etag = cache.set(key, value);
return Response.json(value, {
headers: {
ETag: `"${etag}"`,
"Cache-Control": "private, max-age=60",
"X-Cache-Hit-Rate": `${cache.stats().hitRate}%`,
},
});
};
}
// Example: cache GitHub's API for a minute.
const cache = new ResponseCache<object>({ ttl: 60_000, max: 500 });
export const handler = cached(cache, async (url) => {
const res = await fetch(`https://api.github.com${url.pathname}`);
if (!res.ok) throw new Error(`GitHub returned ${res.status}`);
return res.json();
});</textarea>
</section>
<section id="use">
<h2>Get started</h2>
<p class="section-lead">Pick how you're using it. Every option works with the same 50+ languages and themes.</p>
<div class="tabs" role="tablist" aria-label="Ways to use codelight.js">
<button type="button" role="tab" id="tab-basic" aria-controls="panel-basic" aria-selected="true">Basic usage</button>
<button type="button" role="tab" id="tab-cdn" aria-controls="panel-cdn" aria-selected="false">CDN</button>
<button type="button" role="tab" id="tab-npm" aria-controls="panel-npm" aria-selected="false">npm & bundlers</button>
<button type="button" role="tab" id="tab-react" aria-controls="panel-react" aria-selected="false">React</button>
<button type="button" role="tab" id="tab-node" aria-controls="panel-node" aria-selected="false">Node & servers</button>
<button type="button" role="tab" id="tab-live" aria-controls="panel-live" aria-selected="false">Live code</button>
<button type="button" role="tab" id="tab-detect" aria-controls="panel-detect" aria-selected="false">Detect language</button>
<button type="button" role="tab" id="tab-options" aria-controls="panel-options" aria-selected="false">Options</button>
</div>
<div class="panel" role="tabpanel" id="panel-basic" aria-labelledby="tab-basic">
<h3>1. Add the stylesheet and the script</h3>
<div class="snippet"><pre><code class="language-html"><!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codelight.js@1.x/build/styles/default.min.css">
</head>
<body>
...
<script src="https://cdn.jsdelivr.net/npm/codelight.js@1.x/build/codelight.min.js"></script>
<script>codelight.highlightAll();</script>
</body>
</html></code></pre></div>
<h3>2. Mark up your code</h3>
<p>Put the code in a <code><code></code> inside a <code><pre></code>, and name the language with a <code>language-xxx</code> class, the way the HTML spec recommends. Markdown renderers already produce this.</p>
<div class="snippet"><pre><code class="language-html"><pre><code class="language-css">p { color: red }</code></pre></code></pre></div>
<p>The short form <code>lang-xxx</code>, the class on the <code><pre></code> instead, or a <code>data-lang="python"</code> attribute all work too. Any name or alias from the list below is fine.</p>
<ul class="notes">
<li><b>Escape <code><</code> and <code>&</code></b> inside code, as <code>&lt;</code> and <code>&amp;</code>, or the browser reads them as HTML before codelight.js sees them.</li>
<li><b>Skip a block:</b> add <code>nohighlight</code> or <code>language-none</code>.</li>
<li><b>No language?</b> The block still gets the theme's colours and background, as plain text.</li>
<li><b>Added code later?</b> Call <code>codelight.highlightAll(element)</code> for just that part of the page. Blocks already highlighted are skipped, so calling it again is safe.</li>
<li><b>One block at a time:</b> <code>codelight.highlightElement(codeElement, "ts")</code>.</li>
<li><b>Coming from highlight.js or Prism?</b> Your markup works as it is, and so do <code>highlightAll()</code> and <code>highlightElement()</code>. See the <a href="https://github.com/codelightjs/codelight.js/blob/main/docs/migrating.md">switching guide</a>.</li>
</ul>
<form class="try" action="https://codepen.io/pen/define" method="POST" target="_blank" id="try-codepen">
<input type="hidden" name="data" id="codepen-data">
<button class="btn primary" type="submit">Try it on CodePen ↗</button>
<span>Opens a ready-made example you can edit.</span>
</form>
</div>
<div class="panel" role="tabpanel" id="panel-cdn" aria-labelledby="tab-cdn" hidden>
<h3>jsDelivr</h3>
<div class="snippet"><pre><code class="language-html"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codelight.js@1.x/build/styles/default.min.css">
<script src="https://cdn.jsdelivr.net/npm/codelight.js@1.x/build/codelight.min.js"></script></code></pre></div>
<h3>unpkg</h3>
<div class="snippet"><pre><code class="language-html"><link rel="stylesheet" href="https://unpkg.com/codelight.js@1.x/build/styles/default.min.css">
<script src="https://unpkg.com/codelight.js@1.x/build/codelight.min.js"></script></code></pre></div>
<h3>As an ES module</h3>
<div class="snippet"><pre><code class="language-html"><script type="module">
import codelight from "https://cdn.jsdelivr.net/npm/codelight.js@1.x/es/codelight.js";
codelight.highlightAll();
</script></code></pre></div>
<ul class="notes">
<li><b><code>@1.x</code></b> always loads the newest 1.x release, which never has breaking changes. To lock an exact version, use it instead, for example <code>@1.4.0</code>.</li>
<li><b>Themes:</b> <code>default.min.css</code> follows the system's light or dark setting. <code>light.min.css</code> and <code>dark.min.css</code> are always light or always dark.</li>
<li><b>All 50+ languages are in the one file</b> (16 KB gzipped), so there's nothing else to load.</li>
</ul>
</div>
<div class="panel" role="tabpanel" id="panel-npm" aria-labelledby="tab-npm" hidden>
<h3>Install</h3>
<div class="snippet"><pre><code class="language-console">$ npm install codelight.js</code></pre></div>
<h3>Import</h3>
<div class="snippet"><pre><code class="language-js">import codelight from "codelight.js";
import "codelight.js/styles/default.css";
codelight.highlightAll();</code></pre></div>
<p>Named imports work too, and TypeScript types are included:</p>
<div class="snippet"><pre><code class="language-ts">import { highlight, highlightAll, mount, splitFences } from "codelight.js";</code></pre></div>
<ul class="notes">
<li><b>Works with any bundler,</b> such as Vite, webpack or esbuild: ES modules and CommonJS are both included.</li>
<li><b>No dependencies</b>, so it adds nothing else to your bundle.</li>
</ul>
</div>
<div class="panel" role="tabpanel" id="panel-react" aria-labelledby="tab-react" hidden>
<h3>The component</h3>
<div class="snippet"><pre><code class="language-tsx">import { CodeLight } from "codelight.js/react";
import "codelight.js/styles/default.css";
export function Answer({ code }: { code: string }) {
return <CodeLight code={code} lang="ts" lineNumbers copyButton />;
}</code></pre></div>
<ul class="notes">
<li><b>Pass the whole code on every update.</b> Only the new part is highlighted, and finished lines are never re-rendered, so it's made for code that streams in.</li>
<li><b>Server rendering:</b> the first render is already highlighted HTML, so code is coloured before any JavaScript runs.</li>
<li><b>With react-markdown:</b> return <code><CodeLight></code> from its <code>code</code> component. See the <a href="https://github.com/codelightjs/codelight.js/blob/main/docs/react.md">React guide</a>.</li>
</ul>
</div>
<div class="panel" role="tabpanel" id="panel-node" aria-labelledby="tab-node" hidden>
<h3>Highlight to an HTML string</h3>
<p>Useful for static sites, emails, AMP pages and anything that can't run JavaScript in the browser.</p>
<div class="snippet"><pre><code class="language-js">const { highlight } = require("codelight.js");
const code = "const data = 1;";
const html = `<pre><code class="cl">${highlight(code, "js")}</code></pre>`;</code></pre></div>
<ul class="notes">
<li><b>Every language is already loaded.</b> There's no separate step to load languages.</li>
<li><b>Include a theme</b> (<code>codelight.js/styles/default.css</code>) on the page that shows the HTML.</li>
<li><b>Line numbers on the server:</b> <code>highlight(code, "js", { lineNumbers: true })</code>.</li>
</ul>
</div>
<div class="panel" role="tabpanel" id="panel-live" aria-labelledby="tab-live" hidden>
<h3>Code that keeps changing</h3>
<p>For AI replies, live editors and logs: mount a view once, then write each chunk as it arrives. Finished lines never change. The chat at the top of this page works this way.</p>
<div class="snippet"><pre><code class="language-js">const view = codelight.mount(document.querySelector("#answer"), { lang: "python" });
for await (const chunk of response) {
view.write(chunk);
}</code></pre></div>
<h3>A Markdown reply</h3>
<p><code>splitFences</code> finds the code blocks in a reply that's still arriving, including a fence that hasn't closed yet.</p>
<div class="snippet"><pre><code class="language-js">import { mount, splitFences } from "codelight.js";
for (const part of splitFences(replySoFar)) {
if (part.type === "code") views[i].set(part.code); // only the new text is highlighted
}</code></pre></div>
<ul class="notes">
<li><b>Have the whole text, not chunks?</b> Call <code>view.set(text)</code> on every update; only the new part is written.</li>
<li>More in the <a href="https://github.com/codelightjs/codelight.js/blob/main/docs/streaming.md">streaming guide</a>.</li>
</ul>
</div>
<div class="panel" role="tabpanel" id="panel-detect" aria-labelledby="tab-detect" hidden>
<h3>Try it: paste any code</h3>
<p>The detection add-on guesses the language of code with no tag. When it isn't sure, it shows plain text instead of guessing wrong.</p>
<div class="detect-try">
<label for="detect-input" class="detect-label">Your code</label>
<textarea id="detect-input" spellcheck="false" autocomplete="off">fn main() {
let names = vec!["Asha", "Ravi"];
for name in &names {
println!("Hello, {}!", name);
}
}</textarea>
<div class="detect-result" aria-live="polite"><span>Detected:</span> <b id="detect-lang">…</b> <small id="detect-conf"></small></div>
<div class="snippet"><pre><code id="detect-output" class="cl"></code></pre></div>
<div class="detect-samples" id="detect-samples" aria-label="Examples"></div>
</div>
<h3>Turn it on</h3>
<p>Load the add-on after the main script (8.9 KB gzipped). Blocks without a <code>language-xxx</code> class are then detected by <code>highlightAll()</code>.</p>
<div class="snippet"><pre><code class="language-html"><script src="https://cdn.jsdelivr.net/npm/codelight.js@1.x/build/codelight.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/codelight.js@1.x/build/detect.min.js"></script>
<script>codelight.highlightAll();</script></code></pre></div>
<p>With a bundler, import it once:</p>
<div class="snippet"><pre><code class="language-js">import "codelight.js/detect";
codelight.highlight(code, "auto"); // detect, then highlight
codelight.highlightAuto(code); // { lang, html, confidence }
codelight.mount(element, { lang: "auto" }); // code that streams in</code></pre></div>
<ul class="notes">
<li><b>91% right on code it was never tuned on,</b> and no wrong guesses: the other 9% stayed plain text.</li>
<li><b>While code streams in,</b> it switches language once, as soon as the first lines make it clear.</li>
<li><b>Know the choices?</b> <code>detectLanguage(code, { subset: ["js", "ts", "python"] })</code> is more accurate on short snippets.</li>
<li>More in the <a href="https://github.com/codelightjs/codelight.js/blob/main/docs/detection.md">detection guide</a>.</li>
</ul>
</div>
<div class="panel" role="tabpanel" id="panel-options" aria-labelledby="tab-options" hidden>
<h3>For every block on the page</h3>
<div class="snippet"><pre><code class="language-js">codelight.highlightAll({ lineNumbers: true, copyButton: true });</code></pre></div>
<h3>For one block, with attributes</h3>
<div class="snippet"><pre><code class="language-html"><pre data-line-numbers data-highlight-lines="2,4-5"><code class="language-py">...</code></pre></code></pre></div>
<ul class="notes">
<li><b><code>lineNumbers</code></b> numbers the lines. Copying the code never includes them.</li>
<li><b><code>highlightLines</code></b> highlights lines: <code>"3"</code>, <code>"1,4-6"</code> or <code>[1, 4]</code>.</li>
<li><b><code>copyButton</code></b> adds a Copy button to each block.</li>
<li><b>Dark mode:</b> the default theme follows the system. To force one, add <code>class="dark"</code> or <code>data-theme="dark"</code> to the page. Colours are CSS variables (<code>--cl-keyword</code> and so on), so a theme is a few lines of CSS.</li>
</ul>
</div>
<h3 class="langs-title" id="supported-languages">Supported languages</h3>
<p class="section-lead">Use the name or any alias in <code>language-xxx</code>, <code>data-lang</code> or the <code>lang</code> option.</p>
<label class="lang-search"><span>Find a language</span><input type="search" id="lang-search" placeholder="e.g. python, yml, terraform" autocomplete="off"></label>
<!--LANGUAGES:START (generated from SUPPORTED_LANGUAGES.md by tools/build-demo.mjs)-->
<ul class="lang-list">
<li data-search="bash, shell scripts bash sh shell zsh shellscript"><b>Bash, shell scripts</b><span>bash, sh, shell, zsh, shellscript</span></li>
<li data-search="c c h"><b>C</b><span>c, h</span></li>
<li data-search="c++ cpp c++ cc cxx hpp"><b>C++</b><span>cpp, c++, cc, cxx, hpp</span></li>
<li data-search="c# csharp cs c#"><b>C#</b><span>csharp, cs, c#</span></li>
<li data-search="cmake cmake cmakelists.txt"><b>CMake</b><span>cmake, cmakelists.txt</span></li>
<li data-search="css css"><b>CSS</b><span>css</span></li>
<li data-search="dart dart"><b>Dart</b><span>dart</span></li>
<li data-search="diff, patch diff patch"><b>Diff, patch</b><span>diff, patch</span></li>
<li data-search="dockerfile dockerfile docker containerfile"><b>Dockerfile</b><span>dockerfile, docker, containerfile</span></li>
<li data-search="elixir elixir ex exs heex"><b>Elixir</b><span>elixir, ex, exs, heex</span></li>
<li data-search="go go golang"><b>Go</b><span>go, golang</span></li>
<li data-search="graphql graphql gql"><b>GraphQL</b><span>graphql, gql</span></li>
<li data-search="groovy, gradle groovy gradle gvy jenkinsfile"><b>Groovy, Gradle</b><span>groovy, gradle, gvy, jenkinsfile</span></li>
<li data-search="haskell haskell hs lhs"><b>Haskell</b><span>haskell, hs, lhs</span></li>
<li data-search="html, xml, svg xml html xhtml svg vue svelte"><b>HTML, XML, SVG</b><span>xml, html, xhtml, svg, vue, svelte</span></li>
<li data-search="http requests and responses http https rest rest-client"><b>HTTP requests and responses</b><span>http, https, rest, rest-client</span></li>
<li data-search="ini, .env, .properties ini cfg env dotenv properties editorconfig gitconfig"><b>INI, .env, .properties</b><span>ini, cfg, env, dotenv, properties, editorconfig, gitconfig</span></li>
<li data-search="java java"><b>Java</b><span>java</span></li>
<li data-search="javascript, jsx javascript js jsx mjs cjs node"><b>JavaScript, JSX</b><span>javascript, js, jsx, mjs, cjs, node</span></li>
<li data-search="json json jsonc json5"><b>JSON</b><span>json, jsonc, json5</span></li>
<li data-search="julia julia jl"><b>Julia</b><span>julia, jl</span></li>
<li data-search="kotlin kotlin kt kts"><b>Kotlin</b><span>kotlin, kt, kts</span></li>
<li data-search="latex, tex latex tex context"><b>LaTeX, TeX</b><span>latex, tex, context</span></li>
<li data-search="lua lua luau"><b>Lua</b><span>lua, luau</span></li>
<li data-search="makefile makefile make mk mak gnumakefile"><b>Makefile</b><span>makefile, make, mk, mak, gnumakefile</span></li>
<li data-search="markdown markdown md mdx"><b>Markdown</b><span>markdown, md, mdx</span></li>
<li data-search="mermaid diagrams mermaid mmd"><b>Mermaid diagrams</b><span>mermaid, mmd</span></li>
<li data-search="nginx nginx nginx.conf"><b>nginx</b><span>nginx, nginx.conf</span></li>
<li data-search="nix nix"><b>Nix</b><span>nix</span></li>
<li data-search="php php"><b>PHP</b><span>php</span></li>
<li data-search="plain text plaintext text txt plain"><b>Plain text</b><span>plaintext, text, txt, plain</span></li>
<li data-search="powershell powershell ps1 pwsh ps"><b>PowerShell</b><span>powershell, ps1, pwsh, ps</span></li>
<li data-search="prisma prisma"><b>Prisma</b><span>prisma</span></li>
<li data-search="protocol buffers protobuf proto proto3"><b>Protocol Buffers</b><span>protobuf, proto, proto3</span></li>
<li data-search="python python py python3"><b>Python</b><span>python, py, python3</span></li>
<li data-search="r r rscript"><b>R</b><span>r, rscript</span></li>
<li data-search="ruby ruby rb"><b>Ruby</b><span>ruby, rb</span></li>
<li data-search="rust rust rs"><b>Rust</b><span>rust, rs</span></li>
<li data-search="scala scala sc"><b>Scala</b><span>scala, sc</span></li>
<li data-search="scss, sass, less scss sass less"><b>SCSS, Sass, Less</b><span>scss, sass, less</span></li>
<li data-search="shell session (commands and output) shellsession console terminal shell-session sh-session"><b>Shell session (commands and output)</b><span>shellsession, console, terminal, shell-session, sh-session</span></li>
<li data-search="solidity solidity sol"><b>Solidity</b><span>solidity, sol</span></li>
<li data-search="sql sql postgres postgresql mysql sqlite plsql"><b>SQL</b><span>sql, postgres, postgresql, mysql, sqlite, plsql</span></li>
<li data-search="swift swift"><b>Swift</b><span>swift</span></li>
<li data-search="terraform, hcl hcl terraform tf tfvars opentofu"><b>Terraform, HCL</b><span>hcl, terraform, tf, tfvars, opentofu</span></li>
<li data-search="toml toml"><b>TOML</b><span>toml</span></li>
<li data-search="typescript typescript ts mts cts"><b>TypeScript</b><span>typescript, ts, mts, cts</span></li>
<li data-search="typescript with jsx tsx"><b>TypeScript with JSX</b><span>tsx</span></li>
<li data-search="vba, vb.net, vbscript vba vb vbnet vb.net vbscript vbs visual-basic"><b>VBA, VB.NET, VBScript</b><span>vba, vb, vbnet, vb.net, vbscript, vbs, visual-basic</span></li>
<li data-search="yaml yaml yml"><b>YAML</b><span>yaml, yml</span></li>
<li data-search="zig zig"><b>Zig</b><span>zig</span></li>
</ul>
<!--LANGUAGES:END-->
<p class="lang-none" id="lang-none" hidden>Not in the list? <a href="https://github.com/codelightjs/codelight.js/issues/new/choose">Request it</a>.</p>
</section>
<section>
<h2>Languages</h2>
<p class="section-lead">50+ languages, all in one 16 KB file. Pick one to see it highlighted.</p>
<div class="langs" id="langs" role="toolbar" aria-label="Languages"></div>
<div class="options" role="group" aria-label="Options">
<label><input type="checkbox" id="opt-numbers" checked> Line numbers</label>
<label><input type="checkbox" id="opt-mark"> Highlight lines 3–4</label>
<label><input type="checkbox" id="opt-copy" checked> Copy button</label>
</div>
<div class="example">
<div class="block-head"><span id="ex-name"></span><span id="ex-aliases"></span></div>
<pre><code id="ex-code"></code></pre>
<textarea data-lang="javascript">import { useState } from "react";
export function Counter({ start = 0 }) {
const [count, setCount] = useState(start);
// Each click adds one
return (
<button className="counter" onClick={() => setCount(count + 1)}>
Clicked {count} times
</button>
);
}</textarea>
<textarea data-lang="typescript">interface User {
id: number;
name: string;
email?: string;
}
/** Fetches a user, or null if there isn't one. */
export async function getUser(id: number): Promise<User | null> {
const res = await fetch(`/api/users/${id}`);
if (!res.ok) return null;
return (await res.json()) as User;
}</textarea>
<textarea data-lang="tsx">type Props = { items: string[]; onPick?: (item: string) => void };
export const List = ({ items, onPick }: Props) => (
<ul className="list">
{items.map((item) => (
<li key={item} onClick={() => onPick?.(item)}>
{item}
</li>
))}
</ul>
);</textarea>
<textarea data-lang="json">{
"name": "my-app",
"version": "1.4.0",
"private": true,
"scripts": {
"dev": "vite",
"build": "vite build"
},
"dependencies": { "codelight.js": "^1.0.0" },
"tags": ["demo", null, 42, false]
}</textarea>
<textarea data-lang="python">from dataclasses import dataclass
@dataclass
class Invoice:
"""An invoice with line items."""
customer: str
items: list[tuple[str, float]]
def total(self, tax: float = 0.18) -> float:
subtotal = sum(price for _, price in self.items)
return round(subtotal * (1 + tax), 2) # GST included
invoice = Invoice("Asha", [("Hosting", 499.0), ("Domain", 899.0)])
print(f"{invoice.customer} owes ₹{invoice.total():,.2f}")</textarea>
<textarea data-lang="bash">#!/usr/bin/env bash
set -euo pipefail
BACKUP_DIR="/var/backups/$(date +%F)"
mkdir -p "$BACKUP_DIR"
for db in users orders; do
echo "Backing up $db"
pg_dump --no-owner "$db" | gzip > "$BACKUP_DIR/$db.sql.gz"
done
echo "Done: ${BACKUP_DIR}" # keep 7 days</textarea>
<textarea data-lang="ruby">class Order < ApplicationRecord
belongs_to :customer
validates :total, numericality: { greater_than: 0 }
def paid?
status == :paid # set by the payment webhook
end
def self.recent(limit = 10)
order(created_at: :desc).limit(limit)
end
end</textarea>
<textarea data-lang="php"><?php
namespace App\Http;
final class Greeter
{
public function __construct(private string $name) {}
public function greet(int $times = 1): string
{
// Repeat the greeting
return str_repeat("Hello, {$this->name}! ", $times);
}
}</textarea>
<textarea data-lang="go">package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
name := r.URL.Query().Get("name")
if name == "" {
name = "world"
}
fmt.Fprintf(w, "Hello, %s!", name)
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}</textarea>
<textarea data-lang="rust">use std::collections::HashMap;
#[derive(Debug, Default)]
struct Inventory<'a> {
items: HashMap<&'a str, u32>,
}
impl<'a> Inventory<'a> {
fn add(&mut self, name: &'a str, qty: u32) {
*self.items.entry(name).or_insert(0) += qty;
}
}
fn main() {
let mut inv = Inventory::default();
inv.add("apple", 3);
println!("{:?}", inv);
}</textarea>
<textarea data-lang="java">import java.util.List;
public record Point(int x, int y) {
public double distance() {
return Math.sqrt(x * x + y * y);
}
@Override
public String toString() {
return "(" + x + ", " + y + ")";
}
public static void main(String[] args) {
List.of(new Point(3, 4)).forEach(System.out::println);
}
}</textarea>
<textarea data-lang="c">#include <stdio.h>
#include <string.h>
#define MAX_NAME 32
/* Reverses a string in place. */
void reverse(char *s) {
size_t n = strlen(s);
for (size_t i = 0; i < n / 2; i++) {
char t = s[i];
s[i] = s[n - 1 - i];
s[n - 1 - i] = t;
}
}
int main(void) {
char name[MAX_NAME] = "codelight";
reverse(name);
printf("%s\n", name);
return 0;
}</textarea>
<textarea data-lang="cpp">#include <iostream>
#include <vector>
template <typename T>
T sum(const std::vector<T>& values) {
T total{};
for (const auto& v : values) total += v;
return total;
}
int main() {
std::vector<int> nums{1, 2, 3, 4};
std::cout << "Sum: " << sum(nums) << std::endl;
return 0;
}</textarea>
<textarea data-lang="csharp">using System.Linq;
public record Product(string Name, decimal Price);
public static class Cart
{
// Ignores free items
public static decimal Total(IEnumerable<Product> items) =>
items.Where(p => p.Price > 0).Sum(p => p.Price);
public static string Label(Product p) => $"{p.Name}: {p.Price:C}";
}</textarea>
<textarea data-lang="sql">-- Top customers this year
SELECT c.name, COUNT(o.id) AS orders, SUM(o.total) AS revenue
FROM customers c
JOIN orders o ON o.customer_id = c.id
WHERE o.created_at >= '2026-01-01'
AND o.status <> 'cancelled'
GROUP BY c.name
HAVING SUM(o.total) > 1000
ORDER BY revenue DESC
LIMIT 10;</textarea>
<textarea data-lang="css">:root {
--brand: #6d28d9;
}
/* Primary button */
.button {
padding: 0.5rem 1rem;
border-radius: 8px;
background: var(--brand);
color: white;
transition: transform 150ms ease;
}
.button:hover {
transform: translateY(-1px);
}
@media (max-width: 600px) {
.button { width: 100%; }
}</textarea>
<textarea data-lang="yaml">name: CI
on:
push:
branches: [main]
jobs:
test:
runs-on: ubuntu-latest # Linux runner
strategy:
matrix:
node: [20, 22, 24]
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node }}
- run: npm ci && npm test</textarea>
<textarea data-lang="xml"><!DOCTYPE html>
<html lang="en">
<head>
<title>Menu</title>
<style>
.title { font-family: system-ui; }
</style>
</head>
<body>
<!-- Today's special -->
<h1 class="title">Fish &amp; chips</h1>
<script>
document.querySelector(".title").textContent += "!";
</script>
</body>
</html></textarea>
<textarea data-lang="diff">--- a/src/config.ts
+++ b/src/config.ts
@@ -1,6 +1,6 @@
export const config = {
- retries: 3,
+ retries: 5,
timeout: 10_000,
- debug: true,
+ debug: false,
};</textarea>
<textarea data-lang="kotlin">@Serializable
data class User(val name: String, val age: Int = 0)
// Groups users by the first letter of their name
fun groupUsers(users: List<User>): Map<Char, List<User>> =
users.groupBy { it.name.first().uppercaseChar() }
fun main() {
val users = listOf(User("Asha", 31), User("Arjun"), User("Meera", 27))
for ((letter, group) in groupUsers(users)) {
println("$letter: ${group.joinToString { it.name }}")
}
}</textarea>
<textarea data-lang="swift">import SwiftUI
struct CounterView: View {
@State private var count = 0
let title: String
var body: some View {
VStack(spacing: 12) {
Text("\(title): \(count)")
.font(.title)
Button("Add one") { count += 1 }
}
.padding()
}
}</textarea>
<textarea data-lang="dockerfile"># Build stage
FROM node:24-alpine AS build
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
# Run stage
FROM node:24-alpine
ENV NODE_ENV=production PORT=8080
COPY --from=build /app/dist ./dist
EXPOSE 8080
CMD ["node", "dist/server.js"]</textarea>
<textarea data-lang="toml"># Project settings
[project]
name = "invoice-tools"
version = "1.4.0"
requires-python = ">=3.10"
dependencies = ["httpx>=0.27", "pydantic>=2"]
[tool.ruff]
line-length = 100
exclude = ['migrations']
[tool.pytest.ini_options]
addopts = "-q"
released = 2026-11-30</textarea>
<textarea data-lang="markdown"># Release notes
**codelight.js 1.3** adds line numbers and a *copy button*.
## Upgrade
1. Run `npm i codelight.js@latest`
2. Read the [changelog](https://github.com/codelightjs/codelight.js)
> Nothing breaks: every new option is off by default.
- 8 new languages
- Faster streaming</textarea>
<textarea data-lang="graphql"># A user and their latest posts
query UserWithPosts($id: ID!, $first: Int = 5) {