@scalar/highlight 0.6.0 → 0.7.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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @scalar/highlight
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#11124](https://github.com/scalar/scalar/pull/11124): Ship the `hljs-*` stylesheet as `@scalar/highlight/compat/code.css`
8
+
9
+ This is the `code.css` that `@scalar/code-highlight` ships, unchanged, moved next to the compat layer whose classes it styles. Import `@scalar/highlight/compat/code.css` instead of `@scalar/code-highlight/css/code.css`.
10
+
11
+ Scalar's own packages no longer use `@scalar/code-highlight`. Its code half has a replacement in `@scalar/highlight/compat` and its Markdown half in `@scalar/markdown`.
12
+
13
+ ## 0.6.1
14
+
15
+ ### Patch Changes
16
+
17
+ - [#11004](https://github.com/scalar/scalar/pull/11004): Preserve package output paths and application aliases when building with TypeScript 6.
18
+
3
19
  ## 0.6.0
4
20
 
5
21
  ### Minor Changes
package/README.md CHANGED
@@ -70,6 +70,7 @@ own chunk. The initial chunk with the loader and no languages is 5.0 KB.
70
70
  | `@scalar/highlight/lazy` | `loadLanguage`, for code splitting |
71
71
  | `@scalar/highlight/all` | Every language, registered. For build-time rendering |
72
72
  | `@scalar/highlight/compat` | Drop-in `syntaxHighlight` for `@scalar/code-highlight` |
73
+ | `@scalar/highlight/compat/code.css` | The stylesheet for the `hljs-*` classes `compat` emits |
73
74
 
74
75
  ### Rendering somewhere other than HTML
75
76
 
@@ -246,58 +247,54 @@ reconstruct the source exactly, that scopes come from the shared vocabulary, and
246
247
  tokenizing every truncated prefix terminates and stays consistent — which is what an editor
247
248
  does on every keystroke.
248
249
 
249
- ## Replacing `@scalar/code-highlight`
250
+ ## Migrating from `@scalar/code-highlight`
251
+
252
+ Scalar's own packages no longer use `@scalar/code-highlight`, and it is due to be removed.
253
+ It is two packages wearing one name, and each half has a replacement:
254
+
255
+ | export | now |
256
+ | --- | --- |
257
+ | `syntaxHighlight`, `standardLanguages`, `lowlightLanguageMappings` | `@scalar/highlight/compat` |
258
+ | `css/code.css` | `@scalar/highlight/compat/code.css` |
259
+ | `htmlFromMarkdown`, `getHeadings`, `splitContent`, `isHeading`, `textFromNode` | [`@scalar/markdown`](https://github.com/scalar/scalar/tree/main/packages/markdown) |
260
+ | `rehypeHighlight`, `rehypeAlert` | [`@scalar/markdown`](https://github.com/scalar/scalar/tree/main/packages/markdown) |
261
+ | `basicLanguages`, `jsonYamlLanguages` | **no replacement** — grammars are registered, not passed in |
250
262
 
251
263
  `@scalar/highlight/compat` is a drop-in `syntaxHighlight`. Same signature, same
252
264
  `<pre><code class="hljs language-x">` envelope, same `hljs-*` token classes — so
253
- [`code.css`](https://github.com/scalar/scalar/blob/main/packages/code-highlight/src/css/code.css)
254
- keeps working unchanged and `ScalarCodeBlock` needs one import line changed:
265
+ [`code.css`](src/compat/code.css) styles it unchanged:
255
266
 
256
267
  ```diff
257
268
  -import { standardLanguages, syntaxHighlight } from '@scalar/code-highlight';
258
- +import '@scalar/highlight/all';
269
+ -import '@scalar/code-highlight/css/code.css';
270
+ +import { languages, registerLanguage } from '@scalar/highlight/all';
259
271
  +import { standardLanguages, syntaxHighlight } from '@scalar/highlight/compat';
272
+ +import '@scalar/highlight/compat/code.css';
273
+ +
274
+ +registerLanguage(...languages);
260
275
  ```
261
276
 
262
277
  `standardLanguages` is re-exported with the same key set, so `StandardLanguageKey` is
263
- unchanged and the component's props keep their types.
264
-
265
- ### What it covers, and what it does not
266
-
267
- `@scalar/code-highlight` is two packages wearing one name. The compat layer replaces the
268
- first half only:
269
-
270
- | export | status |
271
- | --- | --- |
272
- | `syntaxHighlight` | covered |
273
- | `standardLanguages` | key-compatible; 49 of 50 names have a grammar |
274
- | `basicLanguages`, `jsonYamlLanguages` | **not covered** — never exported here |
275
- | `lowlightLanguageMappings` | covered |
276
- | `htmlFromMarkdown`, `getHeadings`, `splitContent`, `isHeading`, `textFromNode` | **not covered** |
277
- | `rehypeHighlight`, `rehypeAlert` | **not covered** |
278
-
279
- The Markdown half is a remark/rehype pipeline — GFM, sanitization, GitHub alerts, external
280
- links — that has nothing to do with tokenizing code, and it is not something this library
281
- should grow. A swap keeps `@scalar/code-highlight` as a dependency for
282
- `ScalarMarkdown` and drops it from `ScalarCodeBlock`.
278
+ unchanged and the component's props keep their types. The `languages` option is accepted
279
+ and ignored, since the registry already knows every grammar.
283
280
 
284
281
  The one `standardLanguages` name with no grammar — `plaintext` — renders as escaped,
285
- unhighlighted code, which is exactly what the lowlight pipeline already does for a language
286
- it cannot resolve. `curl` resolves to the Bash grammar, since a curl invocation is a shell
287
- command line; the `language-curl` class `code.css` targets is unaffected, because that
288
- class comes from the name the caller asked for.
282
+ unhighlighted code, which is exactly what the lowlight pipeline did for a language it could
283
+ not resolve. `curl` has a grammar of its own that mirrors the bespoke one the old package
284
+ shipped.
289
285
 
290
286
  ### Verifying it
291
287
 
292
- [`src/compat/compat.test.ts`](src/compat/compat.test.ts) runs the real lowlight pipeline —
293
- imported straight from [`@scalar/code-highlight`](../code-highlight) — beside ours over the
294
- shared sample corpus, and asserts that the rendered text, the `<code>` envelope and the line
295
- elements match exactly. It also ports the four assertions `@scalar/code-highlight` ships
296
- today. Because the comparison runs against the workspace package rather than a copy of it,
297
- a change on either side shows up here.
288
+ [`src/compat/compat.test.ts`](src/compat/compat.test.ts) compares ours against what the
289
+ lowlight pipeline rendered for the shared sample corpus, and asserts that the rendered text,
290
+ the `<code>` envelope and the line elements match exactly. It also ports the four
291
+ assertions `@scalar/code-highlight` ships. The lowlight output is frozen in
292
+ [`test/reference.json`](test/reference.json) rather than imported, so these tests do not
293
+ depend on the old package; [`test/reference.ts`](test/reference.ts) explains what to do when
294
+ a sample changes.
298
295
 
299
296
  Colour is the part that does *not* match exactly, and `pnpm compat:report --detail`
300
- quantifies it: across the whole 42-sample corpus 68.6% of visible characters keep the colour
297
+ quantifies it: across the whole corpus 68.4% of visible characters keep the colour
301
298
  `code.css` gives them, and 82% across the thirteen languages the corpus started with. The
302
299
  rest is our finer scope vocabulary showing through — f-string interiors scoped as code
303
300
  rather than string, docstrings as comments rather than strings, punctuation given its own
@@ -306,7 +303,7 @@ header values, `#` comments and status numbers unstyled. Each round of grammars
306
303
  own floor — the whole corpus, the twenty-six samples before the latest round, and the
307
304
  original thirteen — so a new language cannot dilute a regression in an older one.
308
305
 
309
- For the same three languages `ScalarCodeBlock` shows most often:
306
+ For the same three languages `ScalarCodeBlock` shows most often, measured before the swap:
310
307
 
311
308
  | | gzipped |
312
309
  | --- | ---: |
@@ -354,7 +351,7 @@ From the repository root:
354
351
  ```bash
355
352
  pnpm install
356
353
  pnpm vitest packages/highlight --run # the suite
357
- pnpm --filter @scalar/highlight build # tsc, plus a copy of style.css
354
+ pnpm --filter @scalar/highlight build # tsc, plus a copy of both stylesheets
358
355
  pnpm --filter @scalar/highlight types:check
359
356
  ```
360
357
 
@@ -363,12 +360,11 @@ From this directory:
363
360
  ```bash
364
361
  pnpm bench # throughput per language, for comparing a branch against main
365
362
  pnpm size # bundle size per entry point and per language
366
- pnpm compat:report # @scalar/code-highlight swap report; --detail for colour drift
363
+ pnpm compat:report # colour drift against the old lowlight output; --detail for the breakdown
367
364
  ```
368
365
 
369
- The published package ships zero dependencies. `rolldown` measures bundle size and
370
- `highlight.js` supplies the reference grammars the compat tests differ against; both are
371
- devDependencies and neither reaches consumers.
366
+ The published package ships zero runtime dependencies. `rolldown` measures bundle size; it
367
+ is a devDependency and never reaches consumers.
372
368
 
373
369
  Repository-wide conventions live in the root [`AGENTS.md`](../../AGENTS.md).
374
370
 
@@ -0,0 +1,194 @@
1
+ /* Keep direct stylesheet consumers at the default spacing without competing with container overrides. */
2
+ :where(pre:has(> code.hljs)) {
3
+ line-height: var(--scalar-code-line-height, 1.4);
4
+ }
5
+
6
+ .scalar-app {
7
+ :where(code.hljs) * {
8
+ font-size: inherit;
9
+ font-family: var(--scalar-font-code);
10
+ text-align: left;
11
+ white-space: pre;
12
+ word-spacing: normal;
13
+ word-break: normal;
14
+ word-wrap: normal;
15
+ tab-size: 4;
16
+ }
17
+ code.hljs {
18
+ all: unset;
19
+ font-size: inherit;
20
+ color: var(--scalar-color-2);
21
+ font-family: var(--scalar-font-code);
22
+ counter-reset: linenumber;
23
+ }
24
+ .hljs {
25
+ background: transparent;
26
+ color: var(--scalar-color-2);
27
+ }
28
+
29
+ .hljs .line::before {
30
+ color: var(--scalar-color-3);
31
+ display: inline-block;
32
+ counter-increment: linenumber;
33
+ content: counter(linenumber);
34
+ margin-right: 0.875rem;
35
+ /* Variable is set on the code element by the plugin when line numbers are used */
36
+ min-width: calc(var(--line-digits) * 1ch);
37
+ text-align: right;
38
+ }
39
+ /* ------------------------------------------------------------- */
40
+ /* Data types */
41
+ .hljs-comment,
42
+ .hljs-quote {
43
+ color: var(--scalar-color-3);
44
+ font-style: italic;
45
+ }
46
+
47
+ .hljs-number {
48
+ color: var(--scalar-color-orange);
49
+ }
50
+
51
+ .hljs-regexp,
52
+ .hljs-string {
53
+ color: var(--scalar-color-blue);
54
+ }
55
+
56
+ /** Globals such as `var()` and `!important` */
57
+ .hljs-built_in {
58
+ color: var(--scalar-color-blue);
59
+ }
60
+
61
+ /** Class initializers such as `Array` or `Date` */
62
+ /** Type declarations such as `Record` */
63
+ .hljs-title.class_ {
64
+ color: var(--scalar-color-1);
65
+ }
66
+
67
+ /** Language indicators such as `new`, `const`, or `function` in JS */
68
+ .hljs-keyword {
69
+ color: var(--scalar-color-purple);
70
+ }
71
+
72
+ /** Function names when declaring and calling */
73
+ .hljs-title.function_ {
74
+ color: var(--scalar-color-orange);
75
+ }
76
+
77
+ /** Template substitution */
78
+ .hljs-subst {
79
+ color: var(--scalar-color-blue);
80
+ }
81
+
82
+ /** HTML Tag name */
83
+ .hljs-name {
84
+ color: var(--scalar-color-blue);
85
+ }
86
+
87
+ /** Attribute name (ex. `class`, `id`) */
88
+ .hljs-attr,
89
+ .hljs-attribute {
90
+ color: var(--scalar-color-1);
91
+ }
92
+
93
+ .hljs-addition,
94
+ .hljs-literal,
95
+ .hljs-selector-tag,
96
+ .hljs-type {
97
+ color: var(--scalar-color-green);
98
+ }
99
+
100
+ .hljs-selector-attr,
101
+ .hljs-selector-pseudo {
102
+ color: var(--scalar-color-orange);
103
+ }
104
+ .hljs-doctag {
105
+ color: var(--scalar-color-blue);
106
+ }
107
+
108
+ .hljs-section,
109
+ .hljs-title {
110
+ color: var(--scalar-color-blue);
111
+ }
112
+
113
+ .hljs-selector-id,
114
+ .hljs-template-variable,
115
+ .hljs-variable {
116
+ color: var(--scalar-color-1);
117
+ }
118
+
119
+ .hljs-name,
120
+ .hljs-section,
121
+ .hljs-strong {
122
+ font-weight: var(--scalar-semibold);
123
+ }
124
+
125
+ .hljs-bullet,
126
+ .hljs-link,
127
+ .hljs-meta,
128
+ .hljs-symbol {
129
+ color: var(--scalar-color-blue);
130
+ }
131
+
132
+ .hljs-deletion {
133
+ color: var(--scalar-color-red);
134
+ }
135
+
136
+ .hljs-formula {
137
+ background: var(--scalar-color-1);
138
+ }
139
+
140
+ .hljs-emphasis {
141
+ font-style: italic;
142
+ }
143
+
144
+ /** Hide credentials */
145
+ .credential .credential-value {
146
+ font-size: 0;
147
+ color: transparent;
148
+ }
149
+
150
+ /** Show a few dots instead */
151
+ .credential::after {
152
+ content: "·····";
153
+ color: var(--scalar-color-3);
154
+ user-select: none;
155
+ }
156
+ }
157
+
158
+ /* -------------------------------------------------------------- */
159
+ /* Language specific overrides */
160
+
161
+ /** For HTML we leave the content strings brighter */
162
+ .hljs.language-html {
163
+ color: var(--scalar-color-1);
164
+ }
165
+
166
+ /** For HTML make the attr text different than the content */
167
+ .hljs.language-html .hljs-attr {
168
+ color: var(--scalar-color-2);
169
+ }
170
+
171
+ .hljs.language-curl .hljs-string {
172
+ color: var(--scalar-color-blue);
173
+ }
174
+
175
+ .hljs.language-curl .hljs-literal {
176
+ color: var(--scalar-color-1);
177
+ }
178
+
179
+ /** Compromise here */
180
+ .hljs.language-cpp .hljs-built_in {
181
+ /* color: var(--scalar-color-1); */
182
+ }
183
+
184
+ .hljs.language-php .hljs-variable {
185
+ color: var(--scalar-color-blue);
186
+ }
187
+
188
+ .hljs.language-objectivec .hljs-meta {
189
+ color: var(--scalar-color-1);
190
+ }
191
+
192
+ .hljs.language-objectivec .hljs-built_in {
193
+ color: var(--scalar-color-orange);
194
+ }
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Scope vocabulary -> highlight.js class names.
3
3
  *
4
- * `@scalar/code-highlight` renders through lowlight, so every stylesheet and
4
+ * `@scalar/code-highlight` rendered through lowlight, so every stylesheet and
5
5
  * screenshot in the ecosystem is written against `hljs-*` classes. Emitting
6
- * those classes is what makes a swap invisible: `packages/code-highlight/src/css/code.css`
6
+ * those classes is what makes a swap invisible: `./code.css`
7
7
  * keeps working unchanged, and nothing downstream has to be restyled.
8
8
  *
9
9
  * Values are full class attributes, not suffixes, because highlight.js uses
@@ -2,9 +2,9 @@ import { scopeChain } from '../core/scopes.js';
2
2
  /**
3
3
  * Scope vocabulary -> highlight.js class names.
4
4
  *
5
- * `@scalar/code-highlight` renders through lowlight, so every stylesheet and
5
+ * `@scalar/code-highlight` rendered through lowlight, so every stylesheet and
6
6
  * screenshot in the ecosystem is written against `hljs-*` classes. Emitting
7
- * those classes is what makes a swap invisible: `packages/code-highlight/src/css/code.css`
7
+ * those classes is what makes a swap invisible: `./code.css`
8
8
  * keeps working unchanged, and nothing downstream has to be restyled.
9
9
  *
10
10
  * Values are full class attributes, not suffixes, because highlight.js uses
@@ -14,7 +14,8 @@
14
14
  * What this layer deliberately does *not* cover is the Markdown half of
15
15
  * `@scalar/code-highlight` — `htmlFromMarkdown`, `getHeadings`, `splitContent`,
16
16
  * `rehypeAlert`, `rehypeHighlight`. Those are a remark/rehype pipeline that has
17
- * nothing to do with tokenizing code, and they stay where they are.
17
+ * nothing to do with tokenizing code, and they moved to `@scalar/markdown`,
18
+ * which highlights through `toHast` below.
18
19
  */
19
20
  export type { ToHastOptions } from './hast.js';
20
21
  export { toHast } from './hast.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compat/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,YAAY,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAChD,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,UAAU,EACV,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compat/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,YAAY,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAA;AAC3C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAC/B,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAChD,YAAY,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EACL,uBAAuB,EACvB,aAAa,EACb,UAAU,EACV,wBAAwB,EACxB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,aAAa,CAAA;AACpB,YAAY,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA"}
@@ -14,7 +14,8 @@
14
14
  * What this layer deliberately does *not* cover is the Markdown half of
15
15
  * `@scalar/code-highlight` — `htmlFromMarkdown`, `getHeadings`, `splitContent`,
16
16
  * `rehypeAlert`, `rehypeHighlight`. Those are a remark/rehype pipeline that has
17
- * nothing to do with tokenizing code, and they stay where they are.
17
+ * nothing to do with tokenizing code, and they moved to `@scalar/markdown`,
18
+ * which highlights through `toHast` below.
18
19
  */
19
20
  export { toHast } from './hast.js';
20
21
  export { HLJS_CLASSES, hljsClass } from './hljs.js';
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "code",
17
17
  "performance"
18
18
  ],
19
- "version": "0.6.0",
19
+ "version": "0.7.0",
20
20
  "engines": {
21
21
  "node": ">=22"
22
22
  },
@@ -39,6 +39,11 @@
39
39
  "types": "./dist/compat/index.d.ts",
40
40
  "default": "./dist/compat/index.js"
41
41
  },
42
+ "./compat/code.css": {
43
+ "import": "./dist/compat/code.css",
44
+ "require": "./dist/compat/code.css",
45
+ "default": "./dist/compat/code.css"
46
+ },
42
47
  "./core": {
43
48
  "import": "./dist/core/index.js",
44
49
  "types": "./dist/core/index.d.ts",
@@ -72,14 +77,13 @@
72
77
  "@types/hast": "^3.0.5"
73
78
  },
74
79
  "devDependencies": {
75
- "@scalar/code-highlight": "0.4.11",
76
- "highlight.js": "^11.12.0",
77
- "rolldown": "1.2.14",
78
- "vitest": "4.1.12"
80
+ "@scalar/helpers": "0.19.0",
81
+ "rolldown": "1.3.2",
82
+ "vitest": "5.1.0"
79
83
  },
80
84
  "scripts": {
81
85
  "bench": "tsx bench/bench.ts",
82
- "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && shx cp src/style.css dist/style.css",
86
+ "build": "tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && shx cp src/style.css dist/style.css && shx cp src/compat/code.css dist/compat/code.css",
83
87
  "compat:report": "tsx bench/compat-report.ts",
84
88
  "size": "tsx bench/size.ts",
85
89
  "test": "vitest --run",