@dogsbay/highlight 0.2.0-beta.123 → 0.2.0-beta.125

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/README.md CHANGED
@@ -17,6 +17,35 @@ await highlighter.load(highlightInputs(tree));
17
17
  // pass it as RenderContext.highlighter
18
18
  ```
19
19
 
20
+ ## In a browser
21
+
22
+ Bundle it with code splitting (`esbuild --splitting --format=esm`, or any
23
+ bundler that keeps dynamic `import()`s apart) and each grammar becomes its own
24
+ chunk, fetched the first time `load` names it. Nothing is loaded up front:
25
+ `createHighlighter()` with no `langs` loads no grammar, so a page pays only
26
+ for the languages it shows. Measured with esbuild 0.28, minified, gzipped:
27
+
28
+ | Chunk | Minified | Gzipped |
29
+ |---|---|---|
30
+ | Core (Shiki, the JavaScript regex engine, both themes) | 215 KB | 67 KB |
31
+ | javascript / typescript | 175 / 181 KB | 16.5 / 16.0 KB |
32
+ | html / css | 58 / 49 KB | 11.6 / 11.9 KB |
33
+ | python | 70 KB | 9.2 KB |
34
+ | bash (shellscript) | 41 KB | 6.1 KB |
35
+ | markdown | 59 KB | 5.7 KB |
36
+ | yaml / json / xml | 10 / 3 / 5 KB | 2.3 / 0.8 / 1.2 KB |
37
+ | every grammar | 2.2 MB | 247 KB |
38
+
39
+ A host that renders as you type can call `load(highlightInputs(tree))` before
40
+ each render: it returns at once when everything is loaded, and a block whose
41
+ grammar is still on its way renders plain until the next render.
42
+ `tests/browser-bundle.test.ts` bundles it this way, holds the core under 80 KB
43
+ gzipped (it was 182 KB while it imported render-html's index, which carries
44
+ the whole renderer; it now imports render-html's `lines` and `html` modules),
45
+ and checks that a grammar arrives as its own chunk.
46
+
47
+ ## Grammars
48
+
20
49
  38 grammars, about 2.1 MB minified in all, each loaded when `load` (or the
21
50
  `langs` option; `langs: "all"` loads every one) first names one of its
22
51
  spellings: the grammar's name, its aliases (`sh`, `zsh`), or ours (`py`, `yml`,
@@ -1,6 +1,6 @@
1
- import { type Highlighter } from "@dogsbay/render-html";
2
- export { parseLineRanges } from "@dogsbay/render-html";
3
- export type { CodeOptions, Highlighter } from "@dogsbay/render-html";
1
+ import { type Highlighter } from "@dogsbay/render-html/lines";
2
+ export { parseLineRanges } from "@dogsbay/render-html/lines";
3
+ export type { CodeOptions, Highlighter } from "@dogsbay/render-html/lines";
4
4
  /**
5
5
  * Characters of rendered blocks (and their keys) the highlighter keeps by
6
6
  * default, for library callers: 8M characters is 8–16 MB (a string with any
package/dist/highlight.js CHANGED
@@ -30,9 +30,12 @@ import githubLight from "@shikijs/themes/github-light-default";
30
30
  import githubDark from "@shikijs/themes/github-dark-default";
31
31
  import { LAZY_EMBEDS, LAZY_VIA, LOADERS, SPELLINGS } from "./grammars.js";
32
32
  import { transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, } from "@shikijs/transformers";
33
- import { esc, PLAIN, plainBlock } from "@dogsbay/render-html";
33
+ // The narrow modules, not the package index: the index carries the whole
34
+ // renderer (markdown-it, entities, …), over half the browser bundle otherwise
35
+ import { esc } from "@dogsbay/render-html/html";
36
+ import { PLAIN, plainBlock } from "@dogsbay/render-html/lines";
34
37
  import { stripUnprocessableMarkers } from "@dogsbay/render-html/code-markers";
35
- export { parseLineRanges } from "@dogsbay/render-html";
38
+ export { parseLineRanges } from "@dogsbay/render-html/lines";
36
39
  /** Aliases the grammars do not declare themselves. */
37
40
  const ALIASES = {
38
41
  terminal: "bash",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@dogsbay/highlight",
3
- "version": "0.2.0-beta.123",
4
- "description": "Syntax highlighting for @dogsbay/render-html: Shiki core with the JavaScript regex engine, both themes from one tokenization, a bounded cache. No WebAssembly; Worker-safe",
3
+ "version": "0.2.0-beta.125",
4
+ "description": "Syntax highlighting for @dogsbay/render-html: Shiki core with the JavaScript regex engine, both themes from one tokenization, a bounded cache. No WebAssembly; Worker- and browser-safe, one chunk per grammar when split",
5
5
  "type": "module",
6
6
  "main": "./dist/highlight.js",
7
7
  "types": "./dist/highlight.d.ts",
@@ -25,7 +25,7 @@
25
25
  "@shikijs/themes": "4.3.1",
26
26
  "@shikijs/transformers": "4.3.1",
27
27
  "shiki": "4.3.1",
28
- "@dogsbay/render-html": "0.2.0-beta.123"
28
+ "@dogsbay/render-html": "0.2.0-beta.125"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/node": "^22.20.1",