codelight.js 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +15 -0
- package/README.CDN.md +7 -7
- package/README.md +20 -6
- package/SUPPORTED_LANGUAGES.md +35 -8
- package/build/codelight.js +479 -5
- package/build/codelight.min.js +12 -12
- package/es/{chunk-F46VGBFI.js → chunk-KW6EHF3K.js} +479 -5
- package/es/codelight.js +2 -2
- package/es/react.js +2 -2
- package/lib/{chunk-HSSBKI63.cjs → chunk-MX3F3T5L.cjs} +479 -5
- package/lib/codelight.cjs +17 -17
- package/lib/react.cjs +5 -5
- package/package.json +8 -3
package/CHANGES.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 1.4.0
|
|
4
|
+
|
|
5
|
+
- **23 new languages, 50 in all:** Lua, Dart, Elixir, R, Zig, Scala, Haskell, Julia, nginx, Makefile, INI / .env / .properties, Protocol Buffers, Solidity, Groovy / Gradle, Nix, CMake, Prisma, shell sessions, HTTP, SCSS, Mermaid, LaTeX and VBA / VB.NET.
|
|
6
|
+
- **Shell sessions:** `console` and `terminal` blocks now highlight commands after a prompt (`$ `, `user@host:~$ `, `PS C:\> `) and leave output plain, as GitHub does. They used to be coloured entirely as Bash; `sh`, `bash` and `shell` still are.
|
|
7
|
+
- **SCSS:** `scss`, `sass` and `less` now get `//` comments, `$variables`, mixins and nesting. They used to use the plain CSS rules.
|
|
8
|
+
- Code inside strings is highlighted in the new languages too: `${…}` in Dart, Scala, Groovy and Nix; `#{…}` in Elixir and SCSS; `$(…)` in Julia.
|
|
9
|
+
- nginx: `http` in a URL is no longer coloured as the `http` block.
|
|
10
|
+
- Size: 16.3 KB gzipped with all 50 languages.
|
|
11
|
+
|
|
12
|
+
## 1.3.1
|
|
13
|
+
|
|
14
|
+
- Benchmark against highlight.js, Prism and Shiki: docs/benchmark.md, and npm run bench to run it yourself.
|
|
15
|
+
- CDN links use @1, so they always load the latest 1.x release.
|
|
16
|
+
- Demo: side by side with highlight.js.
|
|
17
|
+
|
|
3
18
|
## 1.3.0
|
|
4
19
|
|
|
5
20
|
- **8 new languages:** Kotlin, Swift, Dockerfile, TOML, Markdown, GraphQL, PowerShell and Terraform/HCL. 27 in all.
|
package/README.CDN.md
CHANGED
|
@@ -6,7 +6,7 @@ Every npm release is on jsDelivr and unpkg. No build step, no install.
|
|
|
6
6
|
|
|
7
7
|
| File | Use |
|
|
8
8
|
|---|---|
|
|
9
|
-
| `build/codelight.min.js` | The script for production. Defines a global `codelight`.
|
|
9
|
+
| `build/codelight.min.js` | The script for production. Defines a global `codelight`. 16 KB gzipped, all 50 languages. |
|
|
10
10
|
| `build/codelight.js` | The same, unminified, for reading and debugging. |
|
|
11
11
|
| `build/styles/default.min.css` | Default theme: light or dark to match the system. |
|
|
12
12
|
| `build/styles/light.min.css` | Light theme. |
|
|
@@ -17,24 +17,24 @@ Unminified `.css` versions of each theme are next to them.
|
|
|
17
17
|
## jsDelivr
|
|
18
18
|
|
|
19
19
|
```html
|
|
20
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codelight.js@1
|
|
21
|
-
<script src="https://cdn.jsdelivr.net/npm/codelight.js@1
|
|
20
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codelight.js@1/build/styles/default.min.css">
|
|
21
|
+
<script src="https://cdn.jsdelivr.net/npm/codelight.js@1/build/codelight.min.js"></script>
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
## unpkg
|
|
25
25
|
|
|
26
26
|
```html
|
|
27
|
-
<link rel="stylesheet" href="https://unpkg.com/codelight.js@1
|
|
28
|
-
<script src="https://unpkg.com/codelight.js@1
|
|
27
|
+
<link rel="stylesheet" href="https://unpkg.com/codelight.js@1/build/styles/default.min.css">
|
|
28
|
+
<script src="https://unpkg.com/codelight.js@1/build/codelight.min.js"></script>
|
|
29
29
|
```
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
`@1` always serves the newest 1.x release, which never has breaking changes. To lock an exact version, use it instead, for example `@1.3.1`. `https://cdn.jsdelivr.net/npm/codelight.js@1` with no path also serves `build/codelight.min.js`.
|
|
32
32
|
|
|
33
33
|
## ES module
|
|
34
34
|
|
|
35
35
|
```html
|
|
36
36
|
<script type="module">
|
|
37
|
-
import codelight from "https://cdn.jsdelivr.net/npm/codelight.js@1
|
|
37
|
+
import codelight from "https://cdn.jsdelivr.net/npm/codelight.js@1/es/codelight.js";
|
|
38
38
|
codelight.highlightAll();
|
|
39
39
|
</script>
|
|
40
40
|
```
|
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ Very fast and lightweight. Only the line being written gets updated, so it stays
|
|
|
15
15
|
|
|
16
16
|
[](https://www.npmjs.com/package/codelight.js)
|
|
17
17
|
[](https://github.com/codelightjs/codelight.js/actions/workflows/ci.yml)
|
|
18
|
-
[](https://www.npmjs.com/package/codelight.js)
|
|
19
19
|
[](https://github.com/codelightjs/codelight.js/blob/main/LICENSE)
|
|
20
20
|
|
|
21
21
|
**[Live demo](https://codelightjs.github.io/)** · **[Documentation](https://github.com/codelightjs/codelight.js/blob/main/docs/README.md)**
|
|
@@ -27,11 +27,25 @@ Very fast and lightweight. Only the line being written gets updated, so it stays
|
|
|
27
27
|
|
|
28
28
|
- **Keeps up with live code.** Each update costs one short line of work, however long the code already is. Re-highlighting the whole block on every update, the usual approach, gets slower as the code grows.
|
|
29
29
|
- **Copes with half-finished Markdown.** Finds code blocks in Markdown that's still arriving, including a fence that hasn't closed and a closing fence that's only half there.
|
|
30
|
-
- **Lightweight, no dependencies.**
|
|
30
|
+
- **Lightweight, no dependencies.** 16 KB gzipped with all 50 languages.
|
|
31
31
|
- **Works anywhere.** Two files from a CDN, an npm package for bundlers, or a React component.
|
|
32
32
|
- **Line numbers, highlighted lines and a copy button,** built in. Copying never includes the line numbers.
|
|
33
33
|
- **Light and dark themes.** Every colour is a CSS variable, and every colour meets WCAG AA contrast.
|
|
34
34
|
|
|
35
|
+
## How fast?
|
|
36
|
+
|
|
37
|
+
A real 282-line TypeScript file arriving 4 characters at a time (2,538 updates), in Edge on a 2020 laptop. After each update the page is updated and laid out.
|
|
38
|
+
|
|
39
|
+
| | Whole file, as it arrives | Per update, late in the file | Finished file, once | Size, gzipped |
|
|
40
|
+
|---|---|---|---|---|
|
|
41
|
+
| **codelight.js** | **7.6 s** | **6.0 ms** | **21 ms** | 16.3 KB, 50 languages |
|
|
42
|
+
| highlight.js | 33.9 s | 24 ms | 23 ms | 11.1 KB, 1 language |
|
|
43
|
+
| Prism | 35.3 s | 30 ms | 23 ms | 7.7 KB, 1 language |
|
|
44
|
+
| Shiki | 218 s | 190 ms | 175 ms | 71.6 KB, 1 language |
|
|
45
|
+
| Shiki + `@shikijs/stream` | 9.0 s | 7.0 ms | 174 ms | 72.2 KB, 1 language |
|
|
46
|
+
|
|
47
|
+
About 4.5× faster than highlight.js and Prism on code that's arriving, and about as fast on finished code. Shiki's streaming package comes close on live code, at six times the size. Method, raw numbers and how to run it yourself: [docs/benchmark.md](https://github.com/codelightjs/codelight.js/blob/main/docs/benchmark.md).
|
|
48
|
+
|
|
35
49
|
## Quick start
|
|
36
50
|
|
|
37
51
|
### On a web page
|
|
@@ -39,8 +53,8 @@ Very fast and lightweight. Only the line being written gets updated, so it stays
|
|
|
39
53
|
Add the stylesheet and the script, then highlight the page. Code blocks need a `language-xxx` class (what Markdown renderers already produce) or a `data-lang` attribute.
|
|
40
54
|
|
|
41
55
|
```html
|
|
42
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codelight.js@1
|
|
43
|
-
<script src="https://cdn.jsdelivr.net/npm/codelight.js@1
|
|
56
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/codelight.js@1/build/styles/default.min.css">
|
|
57
|
+
<script src="https://cdn.jsdelivr.net/npm/codelight.js@1/build/codelight.min.js"></script>
|
|
44
58
|
|
|
45
59
|
<pre><code class="language-python">print("hello")</code></pre>
|
|
46
60
|
|
|
@@ -151,7 +165,7 @@ Full details: [API reference](https://github.com/codelightjs/codelight.js/blob/m
|
|
|
151
165
|
|
|
152
166
|
## Languages
|
|
153
167
|
|
|
154
|
-
|
|
168
|
+
50 languages, including JavaScript, TypeScript, Python, Bash, SQL, HTML, CSS, Kotlin, Swift, Dart, Lua, R, Terraform, Dockerfile, HTTP, Mermaid and LaTeX, plus terminal sessions. See [SUPPORTED_LANGUAGES.md](https://github.com/codelightjs/codelight.js/blob/main/SUPPORTED_LANGUAGES.md) for the full list and every alias. An unknown language shows as plain text, safely escaped.
|
|
155
169
|
|
|
156
170
|
## Themes
|
|
157
171
|
|
|
@@ -201,7 +215,7 @@ codelight.js is built for code that's still arriving. For other jobs there are b
|
|
|
201
215
|
- **Docs sites and blogs** with finished code: [Shiki](https://shiki.style) gives VS Code-accurate colours for 200+ languages, and [highlight.js](https://highlightjs.org) or [Prism](https://prismjs.com) cover far more languages.
|
|
202
216
|
- **A React chat app that already uses Shiki**: [Streamdown](https://streamdown.ai) renders streaming Markdown with Shiki highlighting, and [`@shikijs/stream`](https://shiki.style/packages/stream) streams Shiki itself.
|
|
203
217
|
|
|
204
|
-
codelight.js is the small option: no dependencies, no WebAssembly, any framework, and accurate enough for the
|
|
218
|
+
codelight.js is the small option: no dependencies, no WebAssembly, any framework, and accurate enough for the 50 languages people write most. Its highlighting is rule-based, so unusual syntax can be coloured less precisely than in Shiki.
|
|
205
219
|
|
|
206
220
|
## Contributing
|
|
207
221
|
|
package/SUPPORTED_LANGUAGES.md
CHANGED
|
@@ -1,41 +1,67 @@
|
|
|
1
1
|
# Supported languages
|
|
2
2
|
|
|
3
|
-
All
|
|
3
|
+
All 50 are in every build. Use the name or any alias as the `lang` option, a `data-lang` attribute, or a `language-xxx` class. Names and aliases aren't case-sensitive.
|
|
4
4
|
|
|
5
5
|
| Language | Name | Aliases |
|
|
6
6
|
|---|---|---|
|
|
7
|
-
| Bash, shell | `bash` | `sh`, `shell`, `zsh`, `shellscript
|
|
7
|
+
| Bash, shell scripts | `bash` | `sh`, `shell`, `zsh`, `shellscript` |
|
|
8
8
|
| C | `c` | `h` |
|
|
9
9
|
| C++ | `cpp` | `c++`, `cc`, `cxx`, `hpp` |
|
|
10
10
|
| C# | `csharp` | `cs`, `c#` |
|
|
11
|
-
|
|
|
11
|
+
| CMake | `cmake` | `cmakelists.txt` |
|
|
12
|
+
| CSS | `css` | |
|
|
13
|
+
| Dart | `dart` | |
|
|
12
14
|
| Diff, patch | `diff` | `patch` |
|
|
13
15
|
| Dockerfile | `dockerfile` | `docker`, `containerfile` |
|
|
16
|
+
| Elixir | `elixir` | `ex`, `exs`, `heex` |
|
|
14
17
|
| Go | `go` | `golang` |
|
|
15
18
|
| GraphQL | `graphql` | `gql` |
|
|
19
|
+
| Groovy, Gradle | `groovy` | `gradle`, `gvy`, `jenkinsfile` |
|
|
20
|
+
| Haskell | `haskell` | `hs`, `lhs` |
|
|
16
21
|
| HTML, XML, SVG | `xml` | `html`, `xhtml`, `svg`, `vue`, `svelte` |
|
|
22
|
+
| HTTP requests and responses | `http` | `https`, `rest`, `rest-client` |
|
|
23
|
+
| INI, .env, .properties | `ini` | `cfg`, `env`, `dotenv`, `properties`, `editorconfig`, `gitconfig` |
|
|
17
24
|
| Java | `java` | |
|
|
18
25
|
| JavaScript, JSX | `javascript` | `js`, `jsx`, `mjs`, `cjs`, `node` |
|
|
19
26
|
| JSON | `json` | `jsonc`, `json5` |
|
|
27
|
+
| Julia | `julia` | `jl` |
|
|
20
28
|
| Kotlin | `kotlin` | `kt`, `kts` |
|
|
29
|
+
| LaTeX, TeX | `latex` | `tex`, `context` |
|
|
30
|
+
| Lua | `lua` | `luau` |
|
|
31
|
+
| Makefile | `makefile` | `make`, `mk`, `mak`, `gnumakefile` |
|
|
21
32
|
| Markdown | `markdown` | `md`, `mdx` |
|
|
33
|
+
| Mermaid diagrams | `mermaid` | `mmd` |
|
|
34
|
+
| nginx | `nginx` | `nginx.conf` |
|
|
35
|
+
| Nix | `nix` | |
|
|
22
36
|
| PHP | `php` | |
|
|
23
37
|
| Plain text | `plaintext` | `text`, `txt`, `plain` |
|
|
24
38
|
| PowerShell | `powershell` | `ps1`, `pwsh`, `ps` |
|
|
39
|
+
| Prisma | `prisma` | |
|
|
40
|
+
| Protocol Buffers | `protobuf` | `proto`, `proto3` |
|
|
25
41
|
| Python | `python` | `py`, `python3` |
|
|
42
|
+
| R | `r` | `rscript` |
|
|
26
43
|
| Ruby | `ruby` | `rb` |
|
|
27
44
|
| Rust | `rust` | `rs` |
|
|
45
|
+
| Scala | `scala` | `sc` |
|
|
46
|
+
| SCSS, Sass, Less | `scss` | `sass`, `less` |
|
|
47
|
+
| Shell session (commands and output) | `shellsession` | `console`, `terminal`, `shell-session`, `sh-session` |
|
|
48
|
+
| Solidity | `solidity` | `sol` |
|
|
28
49
|
| SQL | `sql` | `postgres`, `postgresql`, `mysql`, `sqlite`, `plsql` |
|
|
29
50
|
| Swift | `swift` | |
|
|
30
51
|
| Terraform, HCL | `hcl` | `terraform`, `tf`, `tfvars`, `opentofu` |
|
|
31
52
|
| TOML | `toml` | |
|
|
32
53
|
| TypeScript | `typescript` | `ts`, `mts`, `cts` |
|
|
33
54
|
| TypeScript with JSX | `tsx` | |
|
|
55
|
+
| VBA, VB.NET, VBScript | `vba` | `vb`, `vbnet`, `vb.net`, `vbscript`, `vbs`, `visual-basic` |
|
|
34
56
|
| YAML | `yaml` | `yml` |
|
|
57
|
+
| Zig | `zig` | |
|
|
35
58
|
|
|
36
59
|
**Code inside strings is highlighted as code:** `${…}` in JavaScript, TypeScript, Kotlin and Terraform; `{…}` in Python f-strings and C# `$"…"` strings; `\(…)` in Swift; `$(…)` in PowerShell.
|
|
37
60
|
|
|
38
61
|
**Other details:**
|
|
62
|
+
- Shell sessions highlight lines after a prompt (`$ `, `user@host:~$ `, `(venv) $ `, `PS C:> `) as Bash, and leave the output plain. A command ending in `` continues on the next line.
|
|
63
|
+
- HTTP highlights the request or status line and headers, then the body as JSON. `###` separates requests, as in `.http` files.
|
|
64
|
+
- In SCSS, the `//` inside `url(https://…)` isn't treated as a comment.
|
|
39
65
|
- HTML highlights JavaScript inside `<script>` and CSS inside `<style>`. Vue and Svelte files are highlighted as HTML, so their templates, scripts and styles all get colour.
|
|
40
66
|
- JavaScript regex literals are recognised.
|
|
41
67
|
- Bash and Terraform heredocs (`<<EOF` … `EOF`) are recognised.
|
|
@@ -50,13 +76,14 @@ An unknown language shows as plain, escaped text.
|
|
|
50
76
|
import { defineLanguage, registerLanguage } from "codelight.js";
|
|
51
77
|
|
|
52
78
|
registerLanguage(
|
|
53
|
-
"
|
|
79
|
+
"gleam",
|
|
54
80
|
defineLanguage({
|
|
55
|
-
lineComment: ["
|
|
56
|
-
strings: [{ open: '"' }],
|
|
57
|
-
|
|
81
|
+
lineComment: ["//"],
|
|
82
|
+
strings: [{ open: '"', multiline: true }],
|
|
83
|
+
keywords: "as assert case const fn if import let opaque panic pub todo type use",
|
|
84
|
+
constants: "True False Nil",
|
|
85
|
+
classNames: true,
|
|
58
86
|
}),
|
|
59
|
-
["cfg", "conf"],
|
|
60
87
|
);
|
|
61
88
|
```
|
|
62
89
|
|