svelte-highlight 7.8.4 → 7.9.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.
@@ -4,6 +4,9 @@
4
4
  /** @type {any} */
5
5
  export let code;
6
6
 
7
+ /** @type {(import("./languages").LanguageName | (string & {}))[] | undefined} */
8
+ export let languageNames = undefined;
9
+
7
10
  /** @type {boolean} */
8
11
  export let langtag = false;
9
12
 
@@ -26,7 +29,10 @@
26
29
  if (highlighted) dispatch("highlight", { highlighted, language });
27
30
  });
28
31
 
29
- $: ({ value: highlighted, language = "" } = hljs.highlightAuto(code));
32
+ $: ({ value: highlighted, language = "" } = hljs.highlightAuto(
33
+ code,
34
+ languageNames,
35
+ ));
30
36
  </script>
31
37
 
32
38
  <slot {highlighted}>
@@ -1,6 +1,7 @@
1
1
  import type { SvelteComponentTyped } from "svelte";
2
2
  import type { HTMLAttributes } from "svelte/elements";
3
3
  import type { LangtagProps } from "./Highlight.svelte";
4
+ import type { LanguageName } from "./languages";
4
5
 
5
6
  export type HighlightAutoProps = HTMLAttributes<HTMLPreElement> &
6
7
  LangtagProps & {
@@ -8,6 +9,13 @@ export type HighlightAutoProps = HTMLAttributes<HTMLPreElement> &
8
9
  * Specify the text to highlight.
9
10
  */
10
11
  code: any;
12
+
13
+ /**
14
+ * Specify a subset of language names to restrict language auto-detection to.
15
+ * This can improve performance and accuracy.
16
+ * @example ["javascript", "typescript"]
17
+ */
18
+ languageNames?: (LanguageName | (string & {}))[];
11
19
  };
12
20
 
13
21
  export type HighlightAutoEvents = {
package/LangTag.svelte CHANGED
@@ -5,7 +5,7 @@
5
5
  /** @type {string} */
6
6
  export let highlighted;
7
7
 
8
- /** @type {string} */
8
+ /** @type {import('./languages').LanguageName | (string & {})} */
9
9
  export let languageName = "plaintext";
10
10
 
11
11
  /** @type {boolean} */
@@ -1,6 +1,7 @@
1
1
  import type { SvelteComponentTyped } from "svelte";
2
2
  import type { HTMLAttributes } from "svelte/elements";
3
3
  import type { LangtagProps } from "./Highlight.svelte";
4
+ import type { LanguageName } from "./languages";
4
5
 
5
6
  export type LangTagProps = HTMLAttributes<HTMLPreElement> &
6
7
  LangtagProps & {
@@ -18,7 +19,7 @@ export type LangTagProps = HTMLAttributes<HTMLPreElement> &
18
19
  * Provide the language name.
19
20
  * @default "plaintext"
20
21
  */
21
- languageName?: string;
22
+ languageName?: LanguageName | (string & {});
22
23
  };
23
24
 
24
25
  export type LangTagEvents = {};
package/README.md CHANGED
@@ -164,6 +164,25 @@ The `HighlightAuto` component uses the [highlightAuto API](https://highlightjs.r
164
164
  <HighlightAuto {code} />
165
165
  ```
166
166
 
167
+ ### Limiting Language Detection
168
+
169
+ You can restrict [language auto-detection](https://highlightjs.readthedocs.io/en/latest/api.html#highlightauto-value-languagesubset) to a subset using the `languageNames` prop. This can improve performance and accuracy.
170
+
171
+ ```svelte
172
+ <script>
173
+ import { HighlightAuto } from "svelte-highlight";
174
+ import github from "svelte-highlight/styles/github";
175
+
176
+ const code = "const x = 42;";
177
+ </script>
178
+
179
+ <svelte:head>
180
+ {@html github}
181
+ </svelte:head>
182
+
183
+ <HighlightAuto {code} languageNames={["javascript", "typescript"]} />
184
+ ```
185
+
167
186
  ## Line Numbers
168
187
 
169
188
  Use the `LineNumbers` component to render the highlighted code with line numbers.
@@ -489,13 +508,20 @@ In the example below, the `HighlightAuto` component and injected styles are dyna
489
508
 
490
509
  #### Props
491
510
 
492
- | Name | Type | Default value |
493
- | :------ | :-------- | :------------- |
494
- | code | `any` | N/A (required) |
495
- | langtag | `boolean` | `false` |
511
+ | Name | Type | Default value |
512
+ | :-------- | :--------------- | :------------- |
513
+ | code | `any` | N/A (required) |
514
+ | languages | `LanguageName[]` | `undefined` |
515
+ | langtag | `boolean` | `false` |
496
516
 
497
517
  `$$restProps` are forwarded to the top-level `pre` element.
498
518
 
519
+ **Note:** `LanguageName` is a union type of all supported language names, providing autocomplete and type safety. You can import it from `svelte-highlight`:
520
+
521
+ ```ts
522
+ import type { LanguageName } from "svelte-highlight";
523
+ ```
524
+
499
525
  #### Dispatched Events
500
526
 
501
527
  - **on:highlight**: fired after `code` is highlighted
package/index.d.ts CHANGED
@@ -2,4 +2,4 @@ export { default as Highlight, default as default } from "./Highlight.svelte";
2
2
  export { default as HighlightAuto } from "./HighlightAuto.svelte";
3
3
  export { default as HighlightSvelte } from "./HighlightSvelte.svelte";
4
4
  export { default as LineNumbers } from "./LineNumbers.svelte";
5
- export type { LanguageType } from "./languages";
5
+ export type { LanguageType, LanguageName } from "./languages";
@@ -197,3 +197,197 @@ export declare const x86asm: LanguageType<"x86asm">;
197
197
  export declare const xl: LanguageType<"xl">;
198
198
  export declare const xquery: LanguageType<"xquery">;
199
199
  export declare const zephir: LanguageType<"zephir">;
200
+
201
+ export type LanguageName =
202
+ | "1c"
203
+ | "abnf"
204
+ | "accesslog"
205
+ | "actionscript"
206
+ | "ada"
207
+ | "angelscript"
208
+ | "apache"
209
+ | "applescript"
210
+ | "arcade"
211
+ | "arduino"
212
+ | "armasm"
213
+ | "xml"
214
+ | "asciidoc"
215
+ | "aspectj"
216
+ | "autohotkey"
217
+ | "autoit"
218
+ | "avrasm"
219
+ | "awk"
220
+ | "axapta"
221
+ | "bash"
222
+ | "basic"
223
+ | "bnf"
224
+ | "brainfuck"
225
+ | "c"
226
+ | "cal"
227
+ | "capnproto"
228
+ | "ceylon"
229
+ | "clean"
230
+ | "clojure"
231
+ | "clojure-repl"
232
+ | "cmake"
233
+ | "coffeescript"
234
+ | "coq"
235
+ | "cos"
236
+ | "cpp"
237
+ | "crmsh"
238
+ | "crystal"
239
+ | "csharp"
240
+ | "csp"
241
+ | "css"
242
+ | "d"
243
+ | "markdown"
244
+ | "dart"
245
+ | "delphi"
246
+ | "diff"
247
+ | "django"
248
+ | "dns"
249
+ | "dockerfile"
250
+ | "dos"
251
+ | "dsconfig"
252
+ | "dts"
253
+ | "dust"
254
+ | "ebnf"
255
+ | "elixir"
256
+ | "elm"
257
+ | "ruby"
258
+ | "erb"
259
+ | "erlang-repl"
260
+ | "erlang"
261
+ | "excel"
262
+ | "fix"
263
+ | "flix"
264
+ | "fortran"
265
+ | "fsharp"
266
+ | "gams"
267
+ | "gauss"
268
+ | "gcode"
269
+ | "gherkin"
270
+ | "glsl"
271
+ | "gml"
272
+ | "go"
273
+ | "golo"
274
+ | "gradle"
275
+ | "graphql"
276
+ | "groovy"
277
+ | "haml"
278
+ | "handlebars"
279
+ | "haskell"
280
+ | "haxe"
281
+ | "hsp"
282
+ | "http"
283
+ | "hy"
284
+ | "inform7"
285
+ | "ini"
286
+ | "irpf90"
287
+ | "isbl"
288
+ | "java"
289
+ | "javascript"
290
+ | "jboss-cli"
291
+ | "json"
292
+ | "julia"
293
+ | "julia-repl"
294
+ | "kotlin"
295
+ | "lasso"
296
+ | "latex"
297
+ | "ldif"
298
+ | "leaf"
299
+ | "less"
300
+ | "lisp"
301
+ | "livecodeserver"
302
+ | "livescript"
303
+ | "llvm"
304
+ | "lsl"
305
+ | "lua"
306
+ | "makefile"
307
+ | "mathematica"
308
+ | "matlab"
309
+ | "maxima"
310
+ | "mel"
311
+ | "mercury"
312
+ | "mipsasm"
313
+ | "mizar"
314
+ | "perl"
315
+ | "mojolicious"
316
+ | "monkey"
317
+ | "moonscript"
318
+ | "n1ql"
319
+ | "nestedtext"
320
+ | "nginx"
321
+ | "nim"
322
+ | "nix"
323
+ | "node-repl"
324
+ | "nsis"
325
+ | "objectivec"
326
+ | "ocaml"
327
+ | "openscad"
328
+ | "oxygene"
329
+ | "parser3"
330
+ | "pf"
331
+ | "pgsql"
332
+ | "php"
333
+ | "php-template"
334
+ | "plaintext"
335
+ | "pony"
336
+ | "powershell"
337
+ | "processing"
338
+ | "profile"
339
+ | "prolog"
340
+ | "properties"
341
+ | "protobuf"
342
+ | "puppet"
343
+ | "purebasic"
344
+ | "python"
345
+ | "python-repl"
346
+ | "q"
347
+ | "qml"
348
+ | "r"
349
+ | "reasonml"
350
+ | "rib"
351
+ | "roboconf"
352
+ | "routeros"
353
+ | "rsl"
354
+ | "ruleslanguage"
355
+ | "rust"
356
+ | "sas"
357
+ | "scala"
358
+ | "scheme"
359
+ | "scilab"
360
+ | "scss"
361
+ | "shell"
362
+ | "smali"
363
+ | "smalltalk"
364
+ | "sml"
365
+ | "sqf"
366
+ | "sql"
367
+ | "stan"
368
+ | "stata"
369
+ | "step21"
370
+ | "stylus"
371
+ | "subunit"
372
+ | "swift"
373
+ | "taggerscript"
374
+ | "yaml"
375
+ | "tap"
376
+ | "tcl"
377
+ | "thrift"
378
+ | "tp"
379
+ | "twig"
380
+ | "typescript"
381
+ | "vala"
382
+ | "vbnet"
383
+ | "vbscript"
384
+ | "vbscript-html"
385
+ | "verilog"
386
+ | "vhdl"
387
+ | "vim"
388
+ | "wasm"
389
+ | "wren"
390
+ | "x86asm"
391
+ | "xl"
392
+ | "xquery"
393
+ | "zephir";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "svelte-highlight",
3
- "version": "7.8.4",
3
+ "version": "7.9.0",
4
4
  "license": "MIT",
5
5
  "description": "Svelte component library for highlighting code using highlight.js",
6
6
  "author": "Eric Liu (https://github.com/metonym)",
@@ -12,7 +12,7 @@
12
12
  "type": "git",
13
13
  "url": "git+https://github.com/metonym/svelte-highlight.git"
14
14
  },
15
- "homepage": "https://github.com/metonym/svelte-highlight",
15
+ "homepage": "https://svhe.onrender.com/",
16
16
  "bugs": "https://github.com/metonym/svelte-highlight/issues",
17
17
  "keywords": [
18
18
  "svelte",