svelte-highlight 7.20.0 → 7.21.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/AnsiOutput.svelte +35 -4
- package/AnsiOutput.svelte.d.ts +7 -0
- package/FileTabs.svelte +77 -4
- package/FileTabs.svelte.d.ts +11 -0
- package/Highlight.svelte +12 -2
- package/Highlight.svelte.d.ts +32 -0
- package/HighlightAuto.svelte +17 -3
- package/HighlightAuto.svelte.d.ts +13 -0
- package/HighlightEditable.svelte +33 -4
- package/HighlightEditable.svelte.d.ts +14 -4
- package/HighlightStream.svelte +118 -13
- package/HighlightStream.svelte.d.ts +20 -0
- package/HighlightStyle.svelte +33 -13
- package/HighlightStyle.svelte.d.ts +10 -1
- package/HighlightSvelte.svelte +12 -2
- package/HighlightSvelte.svelte.d.ts +5 -0
- package/HighlightVirtual.svelte +41 -2
- package/HighlightVirtual.svelte.d.ts +12 -2
- package/LangTag.svelte +4 -0
- package/LangTag.svelte.d.ts +3 -0
- package/LineNumbers.svelte +88 -37
- package/LineNumbers.svelte.d.ts +60 -4
- package/README.md +556 -77
- package/Typewriter.svelte +61 -12
- package/Typewriter.svelte.d.ts +31 -1
- package/ansi.d.ts +42 -2
- package/ansi.js +286 -1
- package/compat.d.ts +8 -1
- package/compat.js +9 -5
- package/css-walk.js +97 -0
- package/engine.d.ts +18 -2
- package/engine.js +101 -13
- package/fence.d.ts +40 -0
- package/fence.js +124 -0
- package/highlight-theme.js +6 -86
- package/incremental-tokenize.js +55 -54
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/langtag.css +5 -0
- package/languages/1c.js +1 -1356
- package/languages/abnf.js +1 -85
- package/languages/accesslog.js +1 -84
- package/languages/actionscript.js +1 -217
- package/languages/ada.js +1 -232
- package/languages/agda.js +1 -98
- package/languages/all.js +62 -281
- package/languages/angelscript.js +1 -173
- package/languages/angular.js +1 -87
- package/languages/apache.js +1 -95
- package/languages/applescript.js +1 -287
- package/languages/arcade.js +1 -1036
- package/languages/arduino.js +1 -6221
- package/languages/armasm.js +1 -547
- package/languages/asciidoc.js +1 -233
- package/languages/aspectj.js +1 -766
- package/languages/assemblyscript.js +1 -60
- package/languages/astro.js +1 -68
- package/languages/autohotkey.js +1 -129
- package/languages/autoit.js +1 -594
- package/languages/avrasm.js +1 -368
- package/languages/awk.js +1 -111
- package/languages/axapta.js +1 -447
- package/languages/baml.d.ts +2 -0
- package/languages/baml.js +3 -0
- package/languages/bash.js +1 -331
- package/languages/basic.js +1 -258
- package/languages/bend.d.ts +2 -0
- package/languages/bend.js +2 -0
- package/languages/bibtex.js +1 -48
- package/languages/bicep.js +1 -143
- package/languages/bitbake.d.ts +2 -0
- package/languages/bitbake.js +4 -0
- package/languages/blade.js +1 -95
- package/languages/blueprint.d.ts +2 -0
- package/languages/blueprint.js +2 -0
- package/languages/bnf.js +1 -49
- package/languages/bpftrace.d.ts +2 -0
- package/languages/bpftrace.js +2 -0
- package/languages/bqn.d.ts +2 -0
- package/languages/bqn.js +2 -0
- package/languages/brainfuck.js +1 -65
- package/languages/c.js +1 -2304
- package/languages/c3.d.ts +2 -0
- package/languages/c3.js +2 -0
- package/languages/caddy.js +1 -133
- package/languages/cairo.js +1 -167
- package/languages/cal.js +1 -193
- package/languages/capnproto.js +1 -101
- package/languages/cedar.js +1 -56
- package/languages/cel.js +1 -102
- package/languages/ceylon.js +1 -184
- package/languages/cisco.d.ts +2 -0
- package/languages/cisco.js +2 -0
- package/languages/civet.d.ts +2 -0
- package/languages/civet.js +5 -0
- package/languages/clarity.js +1 -159
- package/languages/clean.js +1 -103
- package/languages/clojure-repl.js +1 -21
- package/languages/clojure.js +1 -549
- package/languages/cmake.js +1 -221
- package/languages/codeql.d.ts +2 -0
- package/languages/codeql.js +2 -0
- package/languages/coffeescript.js +1 -823
- package/languages/coq.js +1 -443
- package/languages/cos.js +1 -179
- package/languages/cpp.js +1 -2309
- package/languages/cql.js +1 -202
- package/languages/crmsh.js +1 -197
- package/languages/crontab.d.ts +2 -0
- package/languages/crontab.js +3 -0
- package/languages/crystal.js +1 -729
- package/languages/csharp.js +1 -1109
- package/languages/csp.js +1 -52
- package/languages/css.js +1 -219
- package/languages/csv.d.ts +2 -0
- package/languages/csv.js +2 -0
- package/languages/cue.js +1 -147
- package/languages/cypher.js +1 -147
- package/languages/d.js +1 -240
- package/languages/d2.js +1 -120
- package/languages/dart.js +1 -320
- package/languages/datalog.js +1 -96
- package/languages/dax.js +1 -271
- package/languages/delphi.js +1 -464
- package/languages/dhall.js +1 -162
- package/languages/diff.js +1 -33
- package/languages/django.js +1 -212
- package/languages/djot.d.ts +2 -0
- package/languages/djot.js +2 -0
- package/languages/dns.js +1 -127
- package/languages/dockerfile.js +1 -78
- package/languages/dos.js +1 -169
- package/languages/dotenv.js +1 -73
- package/languages/dsconfig.js +1 -72
- package/languages/dtrace.d.ts +2 -0
- package/languages/dtrace.js +2 -0
- package/languages/dts.js +1 -195
- package/languages/dust.js +1 -53
- package/languages/earthfile.js +1 -46
- package/languages/ebnf.js +1 -41
- package/languages/ejs.d.ts +2 -0
- package/languages/ejs.js +4 -0
- package/languages/elixir.js +1 -522
- package/languages/elm.js +1 -168
- package/languages/erb.js +1 -35
- package/languages/erlang-repl.js +1 -104
- package/languages/erlang.js +1 -351
- package/languages/esql.js +1 -116
- package/languages/excel.js +1 -589
- package/languages/fennel.js +1 -98
- package/languages/fish.js +1 -119
- package/languages/fix.js +1 -34
- package/languages/flix.js +1 -103
- package/languages/flux.js +1 -271
- package/languages/fortran.js +1 -626
- package/languages/freedesktop.js +1 -40
- package/languages/fsharp.js +1 -846
- package/languages/gams.js +1 -701
- package/languages/gauss.js +1 -3841
- package/languages/gbnf.d.ts +2 -0
- package/languages/gbnf.js +2 -0
- package/languages/gcode.js +1 -177
- package/languages/gdscript.js +1 -157
- package/languages/gdshader.d.ts +2 -0
- package/languages/gdshader.js +2 -0
- package/languages/gherkin.js +1 -62
- package/languages/gleam.js +1 -116
- package/languages/glsl.js +1 -634
- package/languages/gml.js +1 -3147
- package/languages/go.js +1 -256
- package/languages/golo.js +1 -93
- package/languages/gotmpl.d.ts +2 -0
- package/languages/gotmpl.js +2 -0
- package/languages/gradle.js +1 -229
- package/languages/graphql.js +1 -97
- package/languages/graphviz.d.ts +2 -0
- package/languages/graphviz.js +3 -0
- package/languages/groovy.js +1 -260
- package/languages/groq.js +1 -95
- package/languages/haml.js +1 -107
- package/languages/handlebars.js +1 -364
- package/languages/haproxy.d.ts +2 -0
- package/languages/haproxy.js +2 -0
- package/languages/haskell.js +1 -269
- package/languages/haxe.js +1 -286
- package/languages/hcl.js +1 -149
- package/languages/heex.js +1 -127
- package/languages/helm.d.ts +2 -0
- package/languages/helm.js +3 -0
- package/languages/hlsl.js +1 -305
- package/languages/hocon.d.ts +2 -0
- package/languages/hocon.js +2 -0
- package/languages/hsp.js +1 -486
- package/languages/html.js +1 -210
- package/languages/http.js +1 -80
- package/languages/hurl.js +1 -119
- package/languages/hy.js +1 -419
- package/languages/idris.js +1 -96
- package/languages/imba.d.ts +2 -0
- package/languages/imba.js +4 -0
- package/languages/index.d.ts +134 -9
- package/languages/index.js +340 -279
- package/languages/inform7.js +1 -59
- package/languages/ini.js +1 -85
- package/languages/ink.d.ts +2 -0
- package/languages/ink.js +2 -0
- package/languages/irpf90.js +1 -608
- package/languages/isbl.js +1 -10131
- package/languages/java.js +1 -549
- package/languages/javascript.js +1 -1242
- package/languages/jboss-cli.js +1 -110
- package/languages/jinja.js +1 -106
- package/languages/jmespath.js +1 -94
- package/languages/jq.js +1 -330
- package/languages/json.js +1 -95
- package/languages/json5.js +1 -108
- package/languages/jsonata.js +1 -78
- package/languages/jsonc.js +1 -76
- package/languages/jsonnet.js +1 -140
- package/languages/julia-repl.js +1 -29
- package/languages/julia.js +1 -617
- package/languages/just.js +1 -228
- package/languages/kcl.d.ts +2 -0
- package/languages/kcl.js +2 -0
- package/languages/kconfig.d.ts +2 -0
- package/languages/kconfig.js +2 -0
- package/languages/kdl.js +1 -113
- package/languages/koka.d.ts +2 -0
- package/languages/koka.js +2 -0
- package/languages/kotlin.js +1 -591
- package/languages/kql.js +1 -284
- package/languages/kv.d.ts +2 -0
- package/languages/kv.js +3 -0
- package/languages/lasso.js +1 -564
- package/languages/latex.js +1 -666
- package/languages/ldif.js +1 -37
- package/languages/ldscript.d.ts +2 -0
- package/languages/ldscript.js +2 -0
- package/languages/leaf.js +1 -61
- package/languages/lean.js +1 -116
- package/languages/less.js +1 -798
- package/languages/liquid.js +1 -113
- package/languages/lisp.js +1 -151
- package/languages/livecodeserver.js +1 -824
- package/languages/livescript.js +1 -1078
- package/languages/llvm.js +1 -380
- package/languages/log.d.ts +2 -0
- package/languages/log.js +2 -0
- package/languages/logql.js +1 -121
- package/languages/lookml.d.ts +2 -0
- package/languages/lookml.js +3 -0
- package/languages/lsl.js +1 -126
- package/languages/lua.js +1 -275
- package/languages/luau.js +1 -127
- package/languages/makefile.js +1 -120
- package/languages/markdoc.d.ts +2 -0
- package/languages/markdoc.js +4 -0
- package/languages/markdown.js +1 -222
- package/languages/marko.js +1 -147
- package/languages/mathematica.js +1 -7329
- package/languages/matlab.js +1 -331
- package/languages/maxima.js +1 -2491
- package/languages/mdx.js +1 -158
- package/languages/mel.js +1 -1305
- package/languages/mercury.js +1 -227
- package/languages/mermaid.js +1 -124
- package/languages/mipsasm.js +1 -285
- package/languages/mizar.js +1 -111
- package/languages/modelfile.d.ts +2 -0
- package/languages/modelfile.js +2 -0
- package/languages/mojo.js +1 -135
- package/languages/mojolicious.js +1 -28
- package/languages/monkey.js +1 -201
- package/languages/moonscript.js +1 -330
- package/languages/move.js +1 -151
- package/languages/n1ql.js +1 -371
- package/languages/nestedtext.js +1 -72
- package/languages/nginx.js +1 -197
- package/languages/nickel.js +1 -128
- package/languages/nim.js +1 -202
- package/languages/nix.js +1 -306
- package/languages/node-repl.js +1 -29
- package/languages/nsis.js +1 -452
- package/languages/nushell.js +1 -162
- package/languages/objectivec.js +1 -299
- package/languages/ocaml.js +1 -161
- package/languages/odin.js +1 -178
- package/languages/openscad.js +1 -181
- package/languages/org.d.ts +2 -0
- package/languages/org.js +2 -0
- package/languages/oxygene.js +1 -455
- package/languages/parser3.js +1 -107
- package/languages/perl.js +1 -860
- package/languages/pf.js +1 -164
- package/languages/pgsql.js +1 -1249
- package/languages/php-template.js +1 -24
- package/languages/php.js +1 -1153
- package/languages/pkl.js +1 -196
- package/languages/plaintext.js +1 -13
- package/languages/plantuml.d.ts +2 -0
- package/languages/plantuml.js +2 -0
- package/languages/plsql.d.ts +2 -0
- package/languages/plsql.js +2 -0
- package/languages/polar.js +1 -58
- package/languages/pony.js +1 -128
- package/languages/powerquery.d.ts +2 -0
- package/languages/powerquery.js +2 -0
- package/languages/powershell.js +1 -401
- package/languages/prisma.js +1 -97
- package/languages/processing.js +1 -441
- package/languages/profile.js +1 -62
- package/languages/prolog.js +1 -138
- package/languages/promql.js +1 -206
- package/languages/properties.js +1 -71
- package/languages/protobuf.js +1 -102
- package/languages/prql.js +1 -159
- package/languages/pug.js +1 -122
- package/languages/puppet.js +1 -411
- package/languages/purebasic.js +1 -183
- package/languages/purescript.js +1 -101
- package/languages/python-repl.js +1 -31
- package/languages/python.js +1 -800
- package/languages/q.js +1 -211
- package/languages/qml.js +1 -397
- package/languages/r.js +1 -347
- package/languages/racket.js +1 -146
- package/languages/raku.d.ts +2 -0
- package/languages/raku.js +2 -0
- package/languages/razor.js +1 -418
- package/languages/reasonml.js +1 -203
- package/languages/regex.d.ts +2 -0
- package/languages/regex.js +2 -0
- package/languages/rego.js +1 -181
- package/languages/renpy.d.ts +2 -0
- package/languages/renpy.js +3 -0
- package/languages/rescript.js +1 -202
- package/languages/rib.js +1 -144
- package/languages/roboconf.js +1 -124
- package/languages/roc.d.ts +2 -0
- package/languages/roc.js +2 -0
- package/languages/ron.d.ts +2 -0
- package/languages/ron.js +2 -0
- package/languages/routeros.js +1 -165
- package/languages/rpmspec.d.ts +2 -0
- package/languages/rpmspec.js +2 -0
- package/languages/rsl.js +1 -171
- package/languages/rst.js +1 -112
- package/languages/ruby.js +1 -886
- package/languages/ruleslanguage.js +1 -373
- package/languages/rust.js +1 -400
- package/languages/sas.js +1 -207
- package/languages/scala.js +1 -328
- package/languages/scheme.js +1 -394
- package/languages/scilab.js +1 -186
- package/languages/scss.js +1 -239
- package/languages/shaderlab.d.ts +2 -0
- package/languages/shaderlab.js +3 -0
- package/languages/shell.js +1 -28
- package/languages/slint.d.ts +2 -0
- package/languages/slint.js +2 -0
- package/languages/smali.js +1 -87
- package/languages/smalltalk.js +1 -85
- package/languages/smithy.d.ts +2 -0
- package/languages/smithy.js +2 -0
- package/languages/sml.js +1 -141
- package/languages/snort.d.ts +2 -0
- package/languages/snort.js +2 -0
- package/languages/solidity.js +1 -402
- package/languages/sparql.js +1 -152
- package/languages/splunk.js +1 -132
- package/languages/sqf.js +1 -2802
- package/languages/sql.js +1 -470
- package/languages/stan.js +1 -522
- package/languages/starlark.js +1 -124
- package/languages/stata.js +1 -1899
- package/languages/step21.js +1 -96
- package/languages/structurizr.d.ts +2 -0
- package/languages/structurizr.js +2 -0
- package/languages/stylus.js +1 -264
- package/languages/subunit.js +1 -55
- package/languages/surrealql.js +1 -127
- package/languages/svelte.js +1 -146
- package/languages/swift.js +1 -2241
- package/languages/systemd.d.ts +2 -0
- package/languages/systemd.js +2 -0
- package/languages/taggerscript.js +1 -47
- package/languages/tap.js +1 -44
- package/languages/tcl.js +1 -214
- package/languages/templ.js +1 -253
- package/languages/textproto.d.ts +2 -0
- package/languages/textproto.js +2 -0
- package/languages/thrift.js +1 -125
- package/languages/toml.js +1 -108
- package/languages/tp.js +1 -205
- package/languages/traceql.js +1 -107
- package/languages/tsq.d.ts +2 -0
- package/languages/tsq.js +2 -0
- package/languages/tsql.d.ts +2 -0
- package/languages/tsql.js +2 -0
- package/languages/tsrx.js +1 -111
- package/languages/turtle.d.ts +2 -0
- package/languages/turtle.js +2 -0
- package/languages/twig.js +1 -200
- package/languages/typescript.js +1 -1412
- package/languages/typespec.d.ts +2 -0
- package/languages/typespec.js +2 -0
- package/languages/typst.js +1 -341
- package/languages/uiua.d.ts +2 -0
- package/languages/uiua.js +2 -0
- package/languages/unison.d.ts +2 -0
- package/languages/unison.js +2 -0
- package/languages/v.js +1 -240
- package/languages/vala.js +1 -157
- package/languages/vbnet.js +1 -329
- package/languages/vbscript-html.js +1 -14
- package/languages/vbscript.js +1 -221
- package/languages/vcl.d.ts +2 -0
- package/languages/vcl.js +2 -0
- package/languages/verilog.js +1 -572
- package/languages/verse.d.ts +2 -0
- package/languages/verse.js +2 -0
- package/languages/vhdl.js +1 -225
- package/languages/vim.js +1 -1290
- package/languages/vrl.js +1 -129
- package/languages/vue.js +1 -121
- package/languages/vyper.js +1 -146
- package/languages/wasm.js +1 -136
- package/languages/wgsl.js +1 -372
- package/languages/wit.js +1 -131
- package/languages/wren.js +1 -307
- package/languages/x86asm.js +1 -2326
- package/languages/xl.js +1 -470
- package/languages/xml.js +1 -194
- package/languages/xquery.js +1 -311
- package/languages/yaml.js +1 -263
- package/languages/yang.d.ts +2 -0
- package/languages/yang.js +2 -0
- package/languages/yara.d.ts +2 -0
- package/languages/yara.js +2 -0
- package/languages/yarnspinner.d.ts +2 -0
- package/languages/yarnspinner.js +2 -0
- package/languages/zephir.js +1 -329
- package/languages/zig.js +1 -199
- package/load-language.d.ts +18 -0
- package/load-language.js +26 -1
- package/package.json +17 -1
- package/preprocessor.js +83 -17
- package/scoped.d.ts +10 -3
- package/scoped.js +32 -90
- package/split-lines.js +16 -15
- package/static.d.ts +14 -0
- package/stream-preview.d.ts +19 -0
- package/stream-preview.js +140 -0
- package/styles/1c-light.js +1 -1
- package/styles/3024.js +1 -1
- package/styles/a11y-dark.js +1 -1
- package/styles/a11y-light.js +1 -1
- package/styles/agate.js +1 -1
- package/styles/alebrije-dark.js +1 -1
- package/styles/alebrije-light.js +1 -1
- package/styles/alpenglow-dark.js +1 -1
- package/styles/alpenglow-light.js +1 -1
- package/styles/amaranth-dark.js +1 -1
- package/styles/amaranth-light.js +1 -1
- package/styles/an-old-hope.js +1 -1
- package/styles/anaglyph-dark.js +1 -1
- package/styles/anaglyph-light.js +1 -1
- package/styles/androidstudio.js +1 -1
- package/styles/apathy.js +1 -1
- package/styles/apprentice.js +1 -1
- package/styles/arduino-light.js +1 -1
- package/styles/arta.js +1 -1
- package/styles/ascetic.js +1 -1
- package/styles/ashes.js +1 -1
- package/styles/atelier-cave-light.js +1 -1
- package/styles/atelier-cave.js +1 -1
- package/styles/atelier-dune-light.js +1 -1
- package/styles/atelier-dune.js +1 -1
- package/styles/atelier-estuary-light.js +1 -1
- package/styles/atelier-estuary.js +1 -1
- package/styles/atelier-forest-light.js +1 -1
- package/styles/atelier-forest.js +1 -1
- package/styles/atelier-heath-light.js +1 -1
- package/styles/atelier-heath.js +1 -1
- package/styles/atelier-lakeside-light.js +1 -1
- package/styles/atelier-lakeside.js +1 -1
- package/styles/atelier-plateau-light.js +1 -1
- package/styles/atelier-plateau.js +1 -1
- package/styles/atelier-savanna-light.js +1 -1
- package/styles/atelier-savanna.js +1 -1
- package/styles/atelier-seaside-light.js +1 -1
- package/styles/atelier-seaside.js +1 -1
- package/styles/atelier-sulphurpool-light.js +1 -1
- package/styles/atelier-sulphurpool.js +1 -1
- package/styles/atlas.js +1 -1
- package/styles/atom-one-dark-reasonable.js +1 -1
- package/styles/atom-one-dark.js +1 -1
- package/styles/atom-one-light.js +1 -1
- package/styles/bakelite-dark.js +1 -1
- package/styles/bakelite-light.js +1 -1
- package/styles/base16-github.js +1 -1
- package/styles/base16-ir-black.js +1 -1
- package/styles/base16-monokai.js +1 -1
- package/styles/base16-nord.js +1 -1
- package/styles/bespin.js +1 -1
- package/styles/black-metal-bathory.js +1 -1
- package/styles/black-metal-burzum.js +1 -1
- package/styles/black-metal-dark-funeral.js +1 -1
- package/styles/black-metal-gorgoroth.js +1 -1
- package/styles/black-metal-immortal.js +1 -1
- package/styles/black-metal-khold.js +1 -1
- package/styles/black-metal-marduk.js +1 -1
- package/styles/black-metal-mayhem.js +1 -1
- package/styles/black-metal-nile.js +1 -1
- package/styles/black-metal-venom.js +1 -1
- package/styles/black-metal.js +1 -1
- package/styles/blacklight-dark.js +1 -1
- package/styles/blacklight-light.js +1 -1
- package/styles/brewer.js +1 -1
- package/styles/bright.js +1 -1
- package/styles/brogrammer.js +1 -1
- package/styles/brown-paper.js +1 -1
- package/styles/brush-trees-dark.js +1 -1
- package/styles/brush-trees.js +1 -1
- package/styles/celadon-dark.js +1 -1
- package/styles/celadon-light.js +1 -1
- package/styles/chalk.js +1 -1
- package/styles/circus.js +1 -1
- package/styles/classic-dark.js +1 -1
- package/styles/classic-light.js +1 -1
- package/styles/cobalt-dark.js +1 -1
- package/styles/cobalt-light.js +1 -1
- package/styles/cochineal-dark.js +1 -1
- package/styles/cochineal-light.js +1 -1
- package/styles/codepen-embed.js +1 -1
- package/styles/codeschool.js +1 -1
- package/styles/color-brewer.js +1 -1
- package/styles/colors.js +1 -1
- package/styles/cross-process-dark.js +1 -1
- package/styles/cross-process-light.js +1 -1
- package/styles/cupcake.js +1 -1
- package/styles/cupertino.js +1 -1
- package/styles/cyanotype-dark.js +1 -1
- package/styles/cyanotype-light.js +1 -1
- package/styles/cybertopia-cherry.js +1 -1
- package/styles/cybertopia-dimmer.js +1 -1
- package/styles/cybertopia-icecap.js +1 -1
- package/styles/cybertopia-saturated.js +1 -1
- package/styles/danqing.js +1 -1
- package/styles/darcula.js +1 -1
- package/styles/dark-violet.js +1 -1
- package/styles/dark.js +1 -1
- package/styles/darkmoss.js +1 -1
- package/styles/darktooth.js +1 -1
- package/styles/decaf.js +1 -1
- package/styles/default-dark.js +1 -1
- package/styles/default-light.js +1 -1
- package/styles/default.js +1 -1
- package/styles/devibeans.js +1 -1
- package/styles/dirtysea.js +1 -1
- package/styles/docco.js +1 -1
- package/styles/dracula.js +1 -1
- package/styles/dusk-dark.js +1 -1
- package/styles/dusk-light.js +1 -1
- package/styles/edge-dark.js +1 -1
- package/styles/edge-light.js +1 -1
- package/styles/eighties.js +1 -1
- package/styles/embers.js +1 -1
- package/styles/equilibrium-dark.js +1 -1
- package/styles/equilibrium-gray-dark.js +1 -1
- package/styles/equilibrium-gray-light.js +1 -1
- package/styles/equilibrium-light.js +1 -1
- package/styles/equinox.js +1 -1
- package/styles/espresso.js +1 -1
- package/styles/eva-dim.js +1 -1
- package/styles/eva.js +1 -1
- package/styles/far.js +1 -1
- package/styles/fauve-dark.js +1 -1
- package/styles/fauve-light.js +1 -1
- package/styles/felipec.js +1 -1
- package/styles/ferrofluid-dark.js +1 -1
- package/styles/ferrofluid-light.js +1 -1
- package/styles/flat.js +1 -1
- package/styles/flint-dark.js +1 -1
- package/styles/flint-light.js +1 -1
- package/styles/foundation.js +1 -1
- package/styles/foxfire-dark.js +1 -1
- package/styles/foxfire-light.js +1 -1
- package/styles/framer.js +1 -1
- package/styles/fruit-soda.js +1 -1
- package/styles/gamboge-dark.js +1 -1
- package/styles/gamboge-light.js +1 -1
- package/styles/gigavolt.js +1 -1
- package/styles/github-dark-dimmed.js +1 -1
- package/styles/github-dark.js +1 -1
- package/styles/github.js +1 -1
- package/styles/gml.js +1 -1
- package/styles/google-dark.js +1 -1
- package/styles/google-light.js +1 -1
- package/styles/googlecode.js +1 -1
- package/styles/gradient-dark.js +1 -1
- package/styles/gradient-light.js +1 -1
- package/styles/grayscale-dark.js +1 -1
- package/styles/grayscale-light.js +1 -1
- package/styles/grayscale.js +1 -1
- package/styles/green-screen.js +1 -1
- package/styles/gruvbox-dark-hard.js +1 -1
- package/styles/gruvbox-dark-medium.js +1 -1
- package/styles/gruvbox-dark-pale.js +1 -1
- package/styles/gruvbox-dark-soft.js +1 -1
- package/styles/gruvbox-light-hard.js +1 -1
- package/styles/gruvbox-light-medium.js +1 -1
- package/styles/gruvbox-light-soft.js +1 -1
- package/styles/haar-dark.js +1 -1
- package/styles/haar-light.js +1 -1
- package/styles/hardcore.js +1 -1
- package/styles/harmonic16-dark.js +1 -1
- package/styles/harmonic16-light.js +1 -1
- package/styles/heetch-dark.js +1 -1
- package/styles/heetch-light.js +1 -1
- package/styles/helios.js +1 -1
- package/styles/hojicha-dark.js +1 -1
- package/styles/hojicha-light.js +1 -1
- package/styles/hopscotch.js +1 -1
- package/styles/horizon-dark.js +1 -1
- package/styles/horizon-light.js +1 -1
- package/styles/humanoid-dark.js +1 -1
- package/styles/humanoid-light.js +1 -1
- package/styles/hybrid.js +1 -1
- package/styles/ia-dark.js +1 -1
- package/styles/ia-light.js +1 -1
- package/styles/icy-dark.js +1 -1
- package/styles/idea.js +1 -1
- package/styles/index.js +348 -348
- package/styles/intellij-light.js +1 -1
- package/styles/ir-black.js +1 -1
- package/styles/isbl-editor-dark.js +1 -1
- package/styles/isbl-editor-light.js +1 -1
- package/styles/isotope.js +1 -1
- package/styles/kimber.js +1 -1
- package/styles/kimbie-dark.js +1 -1
- package/styles/kimbie-light.js +1 -1
- package/styles/kintsugi-dark.js +1 -1
- package/styles/kintsugi-light.js +1 -1
- package/styles/letterpress-dark.js +1 -1
- package/styles/letterpress-light.js +1 -1
- package/styles/lichen-dark.js +1 -1
- package/styles/lichen-light.js +1 -1
- package/styles/lightfair.js +1 -1
- package/styles/lioshi.js +1 -1
- package/styles/london-tube.js +1 -1
- package/styles/lumen-dark.js +1 -1
- package/styles/lumen-light.js +1 -1
- package/styles/macintosh.js +1 -1
- package/styles/magula.js +1 -1
- package/styles/mandarinfish-dark.js +1 -1
- package/styles/mandarinfish-light.js +1 -1
- package/styles/marrakesh.js +1 -1
- package/styles/materia.js +1 -1
- package/styles/material-darker.js +1 -1
- package/styles/material-lighter.js +1 -1
- package/styles/material-palenight.js +1 -1
- package/styles/material-vivid.js +1 -1
- package/styles/material.js +1 -1
- package/styles/mellow-purple.js +1 -1
- package/styles/memphis-dark.js +1 -1
- package/styles/memphis-light.js +1 -1
- package/styles/mexico-light.js +1 -1
- package/styles/mocha.js +1 -1
- package/styles/mono-blue.js +1 -1
- package/styles/monokai-sublime.js +1 -1
- package/styles/monokai.js +1 -1
- package/styles/motherboard-dark.js +1 -1
- package/styles/motherboard-light.js +1 -1
- package/styles/nacre-dark.js +1 -1
- package/styles/nacre-light.js +1 -1
- package/styles/nebula.js +1 -1
- package/styles/night-owl.js +1 -1
- package/styles/nnfx-dark.js +1 -1
- package/styles/nnfx-light.js +1 -1
- package/styles/nord.js +1 -1
- package/styles/nova.js +1 -1
- package/styles/obsidian.js +1 -1
- package/styles/ocean.js +1 -1
- package/styles/oceanicnext.js +1 -1
- package/styles/one-light.js +1 -1
- package/styles/onedark.js +1 -1
- package/styles/outrun-dark.js +1 -1
- package/styles/panda-syntax-dark.js +1 -1
- package/styles/panda-syntax-light.js +1 -1
- package/styles/papercolor-dark.js +1 -1
- package/styles/papercolor-light.js +1 -1
- package/styles/paraiso-dark.js +1 -1
- package/styles/paraiso-light.js +1 -1
- package/styles/paraiso.js +1 -1
- package/styles/pasque.js +1 -1
- package/styles/peat-dark.js +1 -1
- package/styles/peat-light.js +1 -1
- package/styles/phd.js +1 -1
- package/styles/pico.js +1 -1
- package/styles/pitaya-dark.js +1 -1
- package/styles/pitaya-light.js +1 -1
- package/styles/pojoaque.js +1 -1
- package/styles/pop.js +1 -1
- package/styles/porple.js +1 -1
- package/styles/purebasic.js +1 -1
- package/styles/qtcreator-dark.js +1 -1
- package/styles/qtcreator-light.js +1 -1
- package/styles/qualia.js +1 -1
- package/styles/railscasts.js +1 -1
- package/styles/rainbow.js +1 -1
- package/styles/rebecca.js +1 -1
- package/styles/ros-pine-dawn.js +1 -1
- package/styles/ros-pine-moon.js +1 -1
- package/styles/ros-pine.js +1 -1
- package/styles/rose-pine-dawn.js +1 -1
- package/styles/rose-pine-moon.js +1 -1
- package/styles/rose-pine.js +1 -1
- package/styles/routeros.js +1 -1
- package/styles/sagelight.js +1 -1
- package/styles/sandcastle.js +1 -1
- package/styles/school-book.js +1 -1
- package/styles/scoria-dark.js +1 -1
- package/styles/scoria-light.js +1 -1
- package/styles/selenite-dark.js +1 -1
- package/styles/selenite-light.js +1 -1
- package/styles/seti-ui.js +1 -1
- package/styles/shades-of-purple.js +1 -1
- package/styles/shapeshifter.js +1 -1
- package/styles/silk-dark.js +1 -1
- package/styles/silk-light.js +1 -1
- package/styles/snazzy.js +1 -1
- package/styles/solar-flare-light.js +1 -1
- package/styles/solar-flare.js +1 -1
- package/styles/solarized-dark.js +1 -1
- package/styles/solarized-light.js +1 -1
- package/styles/spacemacs.js +1 -1
- package/styles/srcery.js +1 -1
- package/styles/stackoverflow-dark.js +1 -1
- package/styles/stackoverflow-light.js +1 -1
- package/styles/strelitzia-dark.js +1 -1
- package/styles/strelitzia-light.js +1 -1
- package/styles/sumi-dark.js +1 -1
- package/styles/sumi-light.js +1 -1
- package/styles/suminagashi-dark.js +1 -1
- package/styles/suminagashi-light.js +1 -1
- package/styles/summercamp.js +1 -1
- package/styles/summerfruit-dark.js +1 -1
- package/styles/summerfruit-light.js +1 -1
- package/styles/sunburst.js +1 -1
- package/styles/synth-midnight-terminal-dark.js +1 -1
- package/styles/synth-midnight-terminal-light.js +1 -1
- package/styles/tango.js +1 -1
- package/styles/tender.js +1 -1
- package/styles/terrazzo-dark.js +1 -1
- package/styles/terrazzo-light.js +1 -1
- package/styles/thermal-dark.js +1 -1
- package/styles/thermal-light.js +1 -1
- package/styles/tidepool-dark.js +1 -1
- package/styles/tidepool-light.js +1 -1
- package/styles/tokyo-night-dark.js +1 -1
- package/styles/tokyo-night-light.js +1 -1
- package/styles/tomorrow-night-blue.js +1 -1
- package/styles/tomorrow-night-bright.js +1 -1
- package/styles/tomorrow-night.js +1 -1
- package/styles/tomorrow.js +1 -1
- package/styles/tourmaline-dark.js +1 -1
- package/styles/tourmaline-light.js +1 -1
- package/styles/tropicalia-dark.js +1 -1
- package/styles/tropicalia-light.js +1 -1
- package/styles/twilight.js +1 -1
- package/styles/unikitty-dark.js +1 -1
- package/styles/unikitty-light.js +1 -1
- package/styles/uranium-dark.js +1 -1
- package/styles/uranium-light.js +1 -1
- package/styles/urushi-dark.js +1 -1
- package/styles/urushi-light.js +1 -1
- package/styles/verdigris-dark.js +1 -1
- package/styles/verdigris-light.js +1 -1
- package/styles/vitriol-dark.js +1 -1
- package/styles/vitriol-light.js +1 -1
- package/styles/vs-dark.js +1 -1
- package/styles/vs.js +1 -1
- package/styles/vs2015.js +1 -1
- package/styles/vulcan.js +1 -1
- package/styles/wet-plate-dark.js +1 -1
- package/styles/wet-plate-light.js +1 -1
- package/styles/windows-10-light.js +1 -1
- package/styles/windows-10.js +1 -1
- package/styles/windows-95-light.js +1 -1
- package/styles/windows-95.js +1 -1
- package/styles/windows-high-contrast-light.js +1 -1
- package/styles/windows-high-contrast.js +1 -1
- package/styles/windows-nt-light.js +1 -1
- package/styles/windows-nt.js +1 -1
- package/styles/woad-dark.js +1 -1
- package/styles/woad-light.js +1 -1
- package/styles/woodland.js +1 -1
- package/styles/xcode-dusk.js +1 -1
- package/styles/xcode.js +1 -1
- package/styles/xt256.js +1 -1
- package/styles/zenburn.js +1 -1
- package/textmate-theme.d.ts +23 -0
- package/textmate-theme.js +89 -0
- package/theme-style.js +61 -11
- package/theme-vars.js +25 -0
- package/theme.d.ts +16 -0
- package/theme.js +80 -0
- package/themes/3024.js +1 -2
- package/themes/a11y-dark.js +1 -2
- package/themes/a11y-light.js +1 -2
- package/themes/agate.js +1 -2
- package/themes/apathy.js +1 -2
- package/themes/apprentice.js +1 -2
- package/themes/ashes.js +1 -2
- package/themes/atelier-cave-light.js +1 -2
- package/themes/atelier-cave.js +1 -2
- package/themes/atelier-dune-light.js +1 -2
- package/themes/atelier-dune.js +1 -2
- package/themes/atelier-estuary-light.js +1 -2
- package/themes/atelier-estuary.js +1 -2
- package/themes/atelier-forest-light.js +1 -2
- package/themes/atelier-forest.js +1 -2
- package/themes/atelier-heath-light.js +1 -2
- package/themes/atelier-heath.js +1 -2
- package/themes/atelier-lakeside-light.js +1 -2
- package/themes/atelier-lakeside.js +1 -2
- package/themes/atelier-plateau-light.js +1 -2
- package/themes/atelier-plateau.js +1 -2
- package/themes/atelier-savanna-light.js +1 -2
- package/themes/atelier-savanna.js +1 -2
- package/themes/atelier-seaside-light.js +1 -2
- package/themes/atelier-seaside.js +1 -2
- package/themes/atelier-sulphurpool-light.js +1 -2
- package/themes/atelier-sulphurpool.js +1 -2
- package/themes/atlas.js +1 -2
- package/themes/base16-github.js +1 -2
- package/themes/base16-ir-black.js +1 -2
- package/themes/base16-monokai.js +1 -2
- package/themes/base16-nord.js +1 -2
- package/themes/bespin.js +1 -2
- package/themes/black-metal-bathory.js +1 -2
- package/themes/black-metal-burzum.js +1 -2
- package/themes/black-metal-dark-funeral.js +1 -2
- package/themes/black-metal-gorgoroth.js +1 -2
- package/themes/black-metal-immortal.js +1 -2
- package/themes/black-metal-khold.js +1 -2
- package/themes/black-metal-marduk.js +1 -2
- package/themes/black-metal-mayhem.js +1 -2
- package/themes/black-metal-nile.js +1 -2
- package/themes/black-metal-venom.js +1 -2
- package/themes/black-metal.js +1 -2
- package/themes/brewer.js +1 -2
- package/themes/bright.js +1 -2
- package/themes/brogrammer.js +1 -2
- package/themes/brown-paper.js +1 -2
- package/themes/brush-trees-dark.js +1 -2
- package/themes/brush-trees.js +1 -2
- package/themes/chalk.js +1 -2
- package/themes/circus.js +1 -2
- package/themes/classic-dark.js +1 -2
- package/themes/classic-light.js +1 -2
- package/themes/codeschool.js +1 -2
- package/themes/colors.js +1 -2
- package/themes/cupcake.js +1 -2
- package/themes/cupertino.js +1 -2
- package/themes/cybertopia-cherry.js +1 -2
- package/themes/cybertopia-dimmer.js +1 -2
- package/themes/cybertopia-icecap.js +1 -2
- package/themes/cybertopia-saturated.js +1 -2
- package/themes/danqing.js +1 -2
- package/themes/darcula.js +1 -2
- package/themes/dark-violet.js +1 -2
- package/themes/darkmoss.js +1 -2
- package/themes/darktooth.js +1 -2
- package/themes/decaf.js +1 -2
- package/themes/default-dark.js +1 -2
- package/themes/default-light.js +1 -2
- package/themes/dirtysea.js +1 -2
- package/themes/dracula.js +1 -2
- package/themes/edge-dark.js +1 -2
- package/themes/edge-light.js +1 -2
- package/themes/eighties.js +1 -2
- package/themes/embers.js +1 -2
- package/themes/equilibrium-dark.js +1 -2
- package/themes/equilibrium-gray-dark.js +1 -2
- package/themes/equilibrium-gray-light.js +1 -2
- package/themes/equilibrium-light.js +1 -2
- package/themes/espresso.js +1 -2
- package/themes/eva-dim.js +1 -2
- package/themes/eva.js +1 -2
- package/themes/felipec.js +1 -2
- package/themes/flat.js +1 -2
- package/themes/framer.js +1 -2
- package/themes/fruit-soda.js +1 -2
- package/themes/gigavolt.js +1 -2
- package/themes/google-dark.js +1 -2
- package/themes/google-light.js +1 -2
- package/themes/gradient-dark.js +1 -2
- package/themes/gradient-light.js +1 -2
- package/themes/grayscale-dark.js +1 -2
- package/themes/grayscale-light.js +1 -2
- package/themes/grayscale.js +1 -2
- package/themes/green-screen.js +1 -2
- package/themes/gruvbox-dark-hard.js +1 -2
- package/themes/gruvbox-dark-medium.js +1 -2
- package/themes/gruvbox-dark-pale.js +1 -2
- package/themes/gruvbox-dark-soft.js +1 -2
- package/themes/gruvbox-light-hard.js +1 -2
- package/themes/gruvbox-light-medium.js +1 -2
- package/themes/gruvbox-light-soft.js +1 -2
- package/themes/hardcore.js +1 -2
- package/themes/harmonic16-dark.js +1 -2
- package/themes/harmonic16-light.js +1 -2
- package/themes/heetch-dark.js +1 -2
- package/themes/heetch-light.js +1 -2
- package/themes/helios.js +1 -2
- package/themes/hopscotch.js +1 -2
- package/themes/horizon-dark.js +1 -2
- package/themes/horizon-light.js +1 -2
- package/themes/humanoid-dark.js +1 -2
- package/themes/humanoid-light.js +1 -2
- package/themes/hybrid.js +1 -2
- package/themes/ia-dark.js +1 -2
- package/themes/ia-light.js +1 -2
- package/themes/icy-dark.js +1 -2
- package/themes/index.js +348 -348
- package/themes/isotope.js +1 -2
- package/themes/kimber.js +1 -2
- package/themes/london-tube.js +1 -2
- package/themes/macintosh.js +1 -2
- package/themes/marrakesh.js +1 -2
- package/themes/materia.js +1 -2
- package/themes/material-darker.js +1 -2
- package/themes/material-lighter.js +1 -2
- package/themes/material-palenight.js +1 -2
- package/themes/material-vivid.js +1 -2
- package/themes/material.js +1 -2
- package/themes/mellow-purple.js +1 -2
- package/themes/mexico-light.js +1 -2
- package/themes/mocha.js +1 -2
- package/themes/nebula.js +1 -2
- package/themes/nnfx-dark.js +1 -2
- package/themes/nnfx-light.js +1 -2
- package/themes/nord.js +1 -2
- package/themes/nova.js +1 -2
- package/themes/ocean.js +1 -2
- package/themes/oceanicnext.js +1 -2
- package/themes/one-light.js +1 -2
- package/themes/onedark.js +1 -2
- package/themes/outrun-dark.js +1 -2
- package/themes/papercolor-dark.js +1 -2
- package/themes/papercolor-light.js +1 -2
- package/themes/paraiso.js +1 -2
- package/themes/pasque.js +1 -2
- package/themes/phd.js +1 -2
- package/themes/pico.js +1 -2
- package/themes/pojoaque.js +1 -2
- package/themes/pop.js +1 -2
- package/themes/porple.js +1 -2
- package/themes/qualia.js +1 -2
- package/themes/railscasts.js +1 -2
- package/themes/rebecca.js +1 -2
- package/themes/ros-pine-dawn.js +1 -2
- package/themes/ros-pine-moon.js +1 -2
- package/themes/ros-pine.js +1 -2
- package/themes/sagelight.js +1 -2
- package/themes/sandcastle.js +1 -2
- package/themes/seti-ui.js +1 -2
- package/themes/shapeshifter.js +1 -2
- package/themes/silk-dark.js +1 -2
- package/themes/silk-light.js +1 -2
- package/themes/snazzy.js +1 -2
- package/themes/solar-flare-light.js +1 -2
- package/themes/solar-flare.js +1 -2
- package/themes/solarized-dark.js +1 -2
- package/themes/solarized-light.js +1 -2
- package/themes/spacemacs.js +1 -2
- package/themes/summercamp.js +1 -2
- package/themes/summerfruit-dark.js +1 -2
- package/themes/summerfruit-light.js +1 -2
- package/themes/synth-midnight-terminal-dark.js +1 -2
- package/themes/synth-midnight-terminal-light.js +1 -2
- package/themes/tango.js +1 -2
- package/themes/tender.js +1 -2
- package/themes/tomorrow-night.js +1 -2
- package/themes/tomorrow.js +1 -2
- package/themes/twilight.js +1 -2
- package/themes/unikitty-dark.js +1 -2
- package/themes/unikitty-light.js +1 -2
- package/themes/vs2015.js +1 -2
- package/themes/vulcan.js +1 -2
- package/themes/windows-10-light.js +1 -2
- package/themes/windows-10.js +1 -2
- package/themes/windows-95-light.js +1 -2
- package/themes/windows-95.js +1 -2
- package/themes/windows-high-contrast-light.js +1 -2
- package/themes/windows-high-contrast.js +1 -2
- package/themes/windows-nt-light.js +1 -2
- package/themes/windows-nt.js +1 -2
- package/themes/woodland.js +1 -2
- package/themes/xcode-dusk.js +1 -2
- package/themes/zenburn.js +1 -2
- package/tokenized-document.d.ts +6 -0
- package/tokenized-document.js +13 -0
- package/typewriter-units.d.ts +13 -0
- package/typewriter-units.js +36 -0
package/README.md
CHANGED
|
@@ -38,6 +38,8 @@ Import languages from `svelte-highlight/languages`.
|
|
|
38
38
|
|
|
39
39
|
See [SUPPORTED_LANGUAGES.md](SUPPORTED_LANGUAGES.md) for a list of supported languages.
|
|
40
40
|
|
|
41
|
+
`code` accepts any value and is coerced with `String(code ?? "")`: an object like `{}` renders as `"[object Object]"`, while `undefined`/`null` render as nothing.
|
|
42
|
+
|
|
41
43
|
```svelte
|
|
42
44
|
<script>
|
|
43
45
|
import Highlight from "svelte-highlight";
|
|
@@ -49,6 +51,16 @@ See [SUPPORTED_LANGUAGES.md](SUPPORTED_LANGUAGES.md) for a list of supported lan
|
|
|
49
51
|
<Highlight language={typescript} {code} />
|
|
50
52
|
```
|
|
51
53
|
|
|
54
|
+
### Wrapping Long Lines
|
|
55
|
+
|
|
56
|
+
By default, overflowing horizontal content is contained by a scrollbar. Set `wrap` to `true` to wrap long lines instead.
|
|
57
|
+
|
|
58
|
+
```svelte
|
|
59
|
+
<Highlight wrap language={typescript} {code} />
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Don't combine `wrap` with `HighlightStream`'s `virtualize` mode or `HighlightVirtual` -- both assume one fixed-height line per row, which wrapping breaks.
|
|
63
|
+
|
|
52
64
|
## Theming
|
|
53
65
|
|
|
54
66
|
Every `highlight.js` theme is also compiled into a **`ThemePalette`**: a typed object of `--shl-*` CSS custom properties plus a shared structural stylesheet (`svelte-highlight/themes/base.css`) that maps `.hljs*` classes to those variables. This is the recommended way to theme new projects — themes are data, scoping is an inline `style` attribute (SSR-safe by construction), and any token is overridable with one CSS line or a Svelte style prop. See [SUPPORTED_THEMES.md](SUPPORTED_THEMES.md) for a list of compiled themes.
|
|
@@ -108,7 +120,9 @@ This renders SSR-identical output — no `<svelte:head>`, no `<style>` tag, just
|
|
|
108
120
|
</HighlightStyle>
|
|
109
121
|
```
|
|
110
122
|
|
|
111
|
-
|
|
123
|
+
The wrapper's inline style carries the plain light value for each var (e.g. `--shl-keyword:#a626a4`) — a baseline every browser can render. A scoped, deduped `<style>` tag (gated behind `@supports (color: light-dark(...))`) overrides it with `--shl-keyword: light-dark(#a626a4, #c678dd)` (etc.) plus `color-scheme: light dark` on browsers that support `light-dark()`. `mode="light"` / `mode="dark"` force `color-scheme: light` / `dark`. Any other `mode` string (the legacy "CSS selector" mode) omits `color-scheme` inline — set it on your own selector for app-controlled switching, e.g. `[data-theme="dark"] { color-scheme: dark }`.
|
|
124
|
+
|
|
125
|
+
See it live, with a mode toggle, on the [dual-palette preview page](https://svhe.onrender.com/preview-dual-palette).
|
|
112
126
|
|
|
113
127
|
**One-line customization — any token, no theme forking:**
|
|
114
128
|
|
|
@@ -159,6 +173,10 @@ Variable names are derived mechanically from the selectors found in `highlight.j
|
|
|
159
173
|
|
|
160
174
|
`base.css` assumes the default `hljs-` class prefix; projects using a custom `classPrefix` should stay on the legacy string path below.
|
|
161
175
|
|
|
176
|
+
`HighlightStyle` also inlines `color-scheme` from the palette(s) it's given — `palette.colorScheme` for a single `theme`, or a value derived from `mode` for a `light`/`dark` pair — so native form controls and scrollbars inside a themed block follow the theme too.
|
|
177
|
+
|
|
178
|
+
`extras` isn't a corner case for every theme — e.g. the `3024` theme's `extras` covers 7 declarations, including `.hljs ::selection`, `.hljs::selection`, `.hljs-operator`, and `.ruby .hljs-property`, all silently dropped when that theme is imported as a `ThemePalette` object (`svelte-highlight/themes/3024`) instead of its `.css` artifact. There's no per-theme fidelity indicator today; [SUPPORTED_THEMES.md](SUPPORTED_THEMES.md) is where one could eventually live.
|
|
179
|
+
|
|
162
180
|
### Creating themes
|
|
163
181
|
|
|
164
182
|
`svelte-highlight/theme` exports a typed, programmatic way to build or derive `ThemePalette` objects, instead of hand-writing `--shl-*` vars against the full scope vocabulary.
|
|
@@ -195,7 +213,7 @@ const midnight = defineTheme({
|
|
|
195
213
|
</HighlightStyle>
|
|
196
214
|
```
|
|
197
215
|
|
|
198
|
-
`roles` are `foreground`, `background`, `comment`, `keyword`, `string`, `literal`, `function`, `type`, `variable`, `property`, `tag`, `punctuation`, `meta`, `addition`, `deletion` — each expands to a documented set of `--shl-*` scope vars. A bare string is shorthand for `{ color: string }`; both roles and `scopes` also accept a `{ color, background, fontStyle, fontWeight, textDecoration }` object. Precedence is `extends` palette vars → `roles` → `scopes` (later layers win per-var, not per-role). `foreground`/`background` are required unless `extends` is given.
|
|
216
|
+
`roles` are `foreground`, `background`, `comment`, `keyword`, `string`, `literal`, `function`, `type`, `variable`, `property`, `tag`, `punctuation`, `meta`, `addition`, `deletion` — each expands to a documented set of `--shl-*` scope vars. A bare string is shorthand for `{ color: string }`; both roles and `scopes` also accept a `{ color, background, fontStyle, fontWeight, textDecoration }` object. Precedence is `extends` palette vars → `roles` → `scopes` (later layers win per-var, not per-role). `foreground`/`background` are required unless `extends` is given. `ROLE_SCOPES` is exported for tooling that wants to enumerate exactly which scopes a role expands to.
|
|
199
217
|
|
|
200
218
|
**`extendTheme()`** derives a new palette from any shipped or user palette with role- or scope-level overrides:
|
|
201
219
|
|
|
@@ -219,6 +237,21 @@ writeFileSync("public/midnight.css", paletteToCss(midnight));
|
|
|
219
237
|
|
|
220
238
|
`defineTheme` output is a plain `ThemePalette` — spreadable, serializable, diffable, and valid everywhere shipped palettes work, per [Themes are data](#theming) above.
|
|
221
239
|
|
|
240
|
+
**`validatePalette()`** self-checks a `ThemePalette` — useful for a hand-built or hand-edited palette, e.g. one assembled via the [Themes are data](#theming) spread pattern above:
|
|
241
|
+
|
|
242
|
+
```js
|
|
243
|
+
import { validatePalette } from "svelte-highlight/theme";
|
|
244
|
+
|
|
245
|
+
const custom = {
|
|
246
|
+
...atomOneDark,
|
|
247
|
+
vars: { ...atomOneDark.vars, "--shl-keyword": "#ff79c6" },
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
validatePalette(custom); // -> [] when clean; otherwise a list of issues
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
It flags a missing/malformed `vars` object, a missing `--shl-fg`/`--shl-bg`, a `vars` key outside the `--shl-*` grammar, and a `--shl-fg`/`--shl-bg` value that doesn't look like a recognized color — never throws. `defineTheme` already runs it (plus an unknown-`scopes`-key check) automatically in dev mode.
|
|
254
|
+
|
|
222
255
|
### Importing VS Code themes
|
|
223
256
|
|
|
224
257
|
`svelte-highlight/theme/textmate` imports VS Code / TextMate theme JSON (thousands of existing editor themes) into a `ThemePalette`:
|
|
@@ -230,7 +263,7 @@ import nightOwl from "./night-owl-color-theme.json" with { type: "json" };
|
|
|
230
263
|
const palette = fromTextMate(nightOwl);
|
|
231
264
|
```
|
|
232
265
|
|
|
233
|
-
`fromTextMate` accepts a **parsed object** only — VS Code themes are often JSONC, so parsing is the caller's job. The scope mapping is best-effort: TextMate scope selectors are matched against a starter table by segment-prefix (`"entity.name.function"` matches `"entity.name.function.method.ts"`), with the most specific (longest) match winning ties broken by the later `tokenColors` entry — the same specificity semantics VS Code itself uses. Entries that don't map to anything are never silently dropped; pass `onWarn` to observe them:
|
|
266
|
+
`fromTextMate` accepts a **parsed object** only — VS Code themes are often JSONC, so parsing is the caller's job. The scope mapping is best-effort: TextMate scope selectors are matched against a starter table by segment-prefix (`"entity.name.function"` matches `"entity.name.function.method.ts"`), with the most specific (longest) match winning ties broken by the later `tokenColors` entry — the same specificity semantics VS Code itself uses. The starter table covers common scopes, including Markdown code spans/fences and invalid/illegal markers; because matching generalizes by prefix, a row like `"keyword"` already resolves any more-specific scope sharing that prefix, so `"keyword.control"` and `"keyword.operator"` resolve differently without needing a dedicated row for each. Entries that don't map to anything are never silently dropped; pass `onWarn` to observe them:
|
|
234
267
|
|
|
235
268
|
```js
|
|
236
269
|
const palette = fromTextMate(nightOwl, {
|
|
@@ -238,9 +271,28 @@ const palette = fromTextMate(nightOwl, {
|
|
|
238
271
|
});
|
|
239
272
|
```
|
|
240
273
|
|
|
274
|
+
To count unmapped entries instead of observing each one as it happens, use `fromTextMateWithWarnings`, which aggregates every `onWarn` call:
|
|
275
|
+
|
|
276
|
+
```js
|
|
277
|
+
import { fromTextMateWithWarnings } from "svelte-highlight/theme/textmate";
|
|
278
|
+
|
|
279
|
+
const { palette, warnings } = fromTextMateWithWarnings(nightOwl);
|
|
280
|
+
// warnings.length is the number of unmapped tokenColors entries
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
When present, `theme.semanticTokenColors` is read as a higher-priority overlay on top of `tokenColors` — matching VS Code's own precedence when semantic highlighting is enabled. It's resolved against a starter table of VS Code's default semantic token types (`namespace`, `class`, `interface`, `enum`, `struct`, `typeParameter`, `type`, `parameter`, `variable`, `enumMember`, `property`, `event`, `decorator`, `label`, `function`, `method`, `macro`, `comment`, `string`, `keyword`, `number`, `regexp`, `operator`); modifiers (`"variable.readonly"`) and language scoping (`"variable:typescript"`) are not resolved — only the base type before the first `.` or `:` is matched.
|
|
284
|
+
|
|
285
|
+
`fromTextMate` never populates `ThemePalette.extras` — `editor.background` is always read as a single solid color assigned straight to `--shl-bg`. This matches VS Code's own model (VS Code doesn't support gradients for `editor.background` either), so it's a deliberate, low-risk scope cut rather than a gap to fix.
|
|
286
|
+
|
|
287
|
+
Real VS Code theme files are usually JSONC (comments, trailing commas), which `fromTextMate` doesn't accept directly. `scripts/import-textmate-theme.ts` is a local dev recipe — not an installed CLI — that strips comments/trailing commas and writes the resulting `ThemePalette` as JSON; copy it into your own project and adapt as needed:
|
|
288
|
+
|
|
289
|
+
```sh
|
|
290
|
+
bun scripts/import-textmate-theme.ts ./night-owl-color-theme.json ./night-owl.palette.json
|
|
291
|
+
```
|
|
292
|
+
|
|
241
293
|
## Styling
|
|
242
294
|
|
|
243
|
-
Import styles from `svelte-highlight/styles`. See [SUPPORTED_STYLES.md](SUPPORTED_STYLES.md) for a list of supported styles. For new projects, prefer [Theming](#theming) above — this is the original, string-based theming path, kept fully supported for backward compatibility.
|
|
295
|
+
Import styles from `svelte-highlight/styles`. See [SUPPORTED_STYLES.md](SUPPORTED_STYLES.md) for a list of supported styles. For new projects, prefer [Theming](#theming) above — this is the original, string-based theming path, kept fully supported for backward compatibility. Legacy styles are stable and will not be removed. One concrete reason to pick this path over `ThemePalette`: `base.css` assumes the default `hljs-` class prefix, so projects using a custom `classPrefix` should stay here.
|
|
244
296
|
|
|
245
297
|
There are two ways to apply `highlight.js` styles.
|
|
246
298
|
|
|
@@ -267,6 +319,10 @@ This component exports `highlight.js` themes in JavaScript. Import the theme fro
|
|
|
267
319
|
<Highlight language={typescript} {code} />
|
|
268
320
|
```
|
|
269
321
|
|
|
322
|
+
Under a strict Content Security Policy without `'unsafe-inline'` for `style-src`, the browser silently drops this injected `<style>` tag with no visible error. Use [CSS StyleSheet](#css-stylesheet) below instead, which is CSP-safe by construction since it's a normal stylesheet reference.
|
|
323
|
+
|
|
324
|
+
This snippet also has no protection against duplicate `<style>` tags: placing it inside a component that's mounted more than once emits one `<style>` tag per mount. For anything mounted more than once, use [`HighlightStyle`](#highlightstyle) instead, which dedupes automatically across instances of the same theme.
|
|
325
|
+
|
|
270
326
|
### CSS StyleSheet
|
|
271
327
|
|
|
272
328
|
Depending on your set-up, importing a CSS StyleSheet in Svelte may require a CSS file loader. SvelteKit/Vite automatically supports this. For Webpack, refer to [examples/webpack](examples/webpack).
|
|
@@ -341,10 +397,22 @@ Wrap each `Highlight` in `HighlightStyle` to keep a theme on that block:
|
|
|
341
397
|
|
|
342
398
|
The component prefixes each selector with a scope class on the wrapper, so the theme only hits markup inside it.
|
|
343
399
|
|
|
344
|
-
`theme` is required. `scopeClass` defaults to a hash of the theme string. Pass your own, or bind it (`bind:scopeClass`) / read it from the slot (`let:scopeClass`).
|
|
400
|
+
`theme` is required. `scopeClass` defaults to a hash of the theme string. Pass your own, or bind it (`bind:scopeClass`) / read it from the slot (`let:scopeClass`). An empty string is treated the same as omitting `scopeClass` — it falls back to the auto-hash. `scopeClass` must be a single valid CSS class name; a value like `"a b"` will warn in the console and won't scope as expected.
|
|
345
401
|
|
|
346
402
|
For a page-wide theme, use `{@html theme}` as shown above.
|
|
347
403
|
|
|
404
|
+
Under a `style-src` CSP that requires a nonce, pass `nonce` and it's attached to the `<style>` tag `HighlightStyle` injects into `<svelte:head>`:
|
|
405
|
+
|
|
406
|
+
```svelte
|
|
407
|
+
<HighlightStyle theme={a11yDark} nonce={cspNonce}>
|
|
408
|
+
<Highlight language={typescript} {code} />
|
|
409
|
+
</HighlightStyle>
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
A single `ThemePalette` (`theme` as an object, not a `light`/`dark` pair) never injects a `<style>` tag at all — only inline vars on the wrapper — so it's unaffected by a `style-src` nonce requirement in the first place; that's a reason to prefer it under a strict CSP.
|
|
413
|
+
|
|
414
|
+
**Known limitation:** on the CSS-string path, server-side rendering emits one `<style>` tag per `HighlightStyle` instance, even when several instances on the page share the exact same theme — the client-side dedupe only kicks in after hydration. This is harmless (CSS is idempotent), but adds extra bytes on pages with many repeated identical-theme instances. The `ThemePalette` object path has no such concern for a single theme, since it never injects a `<style>` tag to begin with.
|
|
415
|
+
|
|
348
416
|
### Dark mode
|
|
349
417
|
|
|
350
418
|
`HighlightStyle` can emit a light and a dark theme together and switch between them. Pass `light` and `dark` instead of `theme`:
|
|
@@ -378,6 +446,8 @@ The `mode` prop controls how the two themes are switched (default `"auto"`):
|
|
|
378
446
|
|
|
379
447
|
Both themes are scoped to the wrapper, so different blocks can use different theme pairs on the same page. When `light` and `dark` are both set they take precedence over `theme`; passing only `theme` keeps the existing single-theme behavior unchanged.
|
|
380
448
|
|
|
449
|
+
The `ThemePalette` object pair path (`light`/`dark` as [`ThemePalette`s](#theming) rather than CSS strings) works the same way, but resolves the pair via `light-dark()` instead of `prefers-color-scheme`/selector gating. On a browser that predates `light-dark()` support, it now falls back to the light theme instead of rendering broken (unset) colors: a scoped, deduped `<style>` tag applies the `light-dark()` values behind `@supports (color: light-dark(...))`, and the wrapper's own inline style carries the plain light value as the pre-`@supports` baseline. Single-theme (`theme` alone, no pair) SSR-identical guarantees are unaffected either way.
|
|
450
|
+
|
|
381
451
|
## Styling with CSS variables
|
|
382
452
|
|
|
383
453
|
Every `Highlight` variant forwards `$$restProps` to its top-level element, so you can style the component using CSS variables without resorting to `:global` overrides or `!important`.
|
|
@@ -408,16 +478,19 @@ These apply to the outer container of every component (the `pre` element for `Hi
|
|
|
408
478
|
|
|
409
479
|
### `LineNumbers` variables
|
|
410
480
|
|
|
411
|
-
| Variable
|
|
412
|
-
|
|
|
413
|
-
| --line-number-color
|
|
414
|
-
| --
|
|
415
|
-
| --
|
|
416
|
-
| --
|
|
417
|
-
| --
|
|
418
|
-
| --
|
|
419
|
-
| --
|
|
420
|
-
| --
|
|
481
|
+
| Variable | Description | Default value |
|
|
482
|
+
| :------------------------ | :------------------------------------------------ | :--------------------------- |
|
|
483
|
+
| --line-number-color | Text color of the line numbers | `currentColor` |
|
|
484
|
+
| --line-number-digit-width | Width of a single gutter digit | `0.6em` |
|
|
485
|
+
| --border-color | Border color of the column of line numbers | `currentColor` |
|
|
486
|
+
| --highlighted-background | Background color of highlighted lines | `rgba(254, 241, 96, 0.2)` |
|
|
487
|
+
| --line-added-background | Background color of `lineStates` `"added"` lines | `rgba(46, 204, 113, 0.15)` |
|
|
488
|
+
| --line-removed-background | Background color of `lineStates` `"removed"` lines | `rgba(231, 76, 60, 0.15)` |
|
|
489
|
+
| --unhighlighted-opacity | Opacity of un-highlighted lines (focus mode) | `1` |
|
|
490
|
+
| --unhighlighted-filter | CSS filter for un-highlighted lines (focus mode) | `none` |
|
|
491
|
+
| --padding | Fallback padding for `--padding-left` / `--padding-right` | `1em` |
|
|
492
|
+
| --padding-left | Left padding for `td` elements | `var(--padding, 1em)` |
|
|
493
|
+
| --padding-right | Right padding for `td` elements | `var(--padding, 1em)` |
|
|
421
494
|
|
|
422
495
|
### `CopyButton` variables
|
|
423
496
|
|
|
@@ -445,6 +518,7 @@ These apply when `langtag` is set to `true`.
|
|
|
445
518
|
| --langtag-color | Text color of the langtag | `inherit` |
|
|
446
519
|
| --langtag-border-radius | Border radius of the langtag | `0` |
|
|
447
520
|
| --langtag-padding | Padding of the langtag | `1em` |
|
|
521
|
+
| --langtag-font-size | Font size of the langtag | `inherit` |
|
|
448
522
|
|
|
449
523
|
### `CodeWindow` variables
|
|
450
524
|
|
|
@@ -469,16 +543,36 @@ These apply when `langtag` is set to `true`.
|
|
|
469
543
|
| --prompt-font-weight | Font weight of the terminal prompt | `700` |
|
|
470
544
|
| --prompt-color | Color of the terminal prompt | `inherit` |
|
|
471
545
|
|
|
546
|
+
### `FileTabs` variables
|
|
547
|
+
|
|
548
|
+
| Variable | Description | Default value |
|
|
549
|
+
| :---------------------- | :--------------------------------------------------------------- | :-------------------------------------------- |
|
|
550
|
+
| --file-tabs-gap | Gap between tabs | `0` |
|
|
551
|
+
| --file-tabs-background | Tab strip background | `inherit` |
|
|
552
|
+
| --tab-overflow-fade | Width of the scroll shadow shown on the overflowing edge | `1.5rem` |
|
|
553
|
+
| --tab-padding | Padding of each tab | `0.5em 1em` |
|
|
554
|
+
| --tab-color | Text color of inactive tabs | `inherit` |
|
|
555
|
+
| --tab-background | Background color of inactive tabs | `transparent` |
|
|
556
|
+
| --tab-inactive-opacity | Opacity of inactive tabs (active and hovered tabs stay opaque) | `0.55` |
|
|
557
|
+
| --tab-active-color | Text color of the active tab | the highlighted code's text color |
|
|
558
|
+
| --tab-active-background | Background color of the active tab | the highlighted code's background |
|
|
559
|
+
| --tab-focus-outline | Keyboard focus outline of a tab | `2px solid currentColor` |
|
|
560
|
+
|
|
472
561
|
## Svelte Syntax Highlighting
|
|
473
562
|
|
|
474
|
-
Use the `HighlightSvelte` component for Svelte syntax highlighting.
|
|
563
|
+
Use the `HighlightSvelte` component for Svelte syntax highlighting. Its grammar understands Svelte 5 runes (`$state`, `$derived`, `$effect` and its suffixed forms, `$props.id`, `$inspect.trace`), store auto-subscription (`$store`, `$store()`, `$store.prop`), `lang="ts"`/`context="module"` script-block resolution, and directive shorthand (`on:`, `bind:`, `use:`, and friends) — genuinely ahead of generic HTML-plus-embedded-JS Svelte highlighting, which has no notion that runes exist.
|
|
475
564
|
|
|
476
565
|
```svelte
|
|
477
566
|
<script>
|
|
478
567
|
import { HighlightSvelte } from "svelte-highlight";
|
|
479
568
|
import github from "svelte-highlight/styles/github";
|
|
480
569
|
|
|
481
|
-
const code = `<
|
|
570
|
+
const code = `<script>
|
|
571
|
+
let count = $state(0);
|
|
572
|
+
let doubled = $derived(count * 2);
|
|
573
|
+
<\/script>
|
|
574
|
+
|
|
575
|
+
<button on:click={() => count++}>{doubled} (store: {$externalCount})</button>`;
|
|
482
576
|
</script>
|
|
483
577
|
|
|
484
578
|
<svelte:head>
|
|
@@ -488,12 +582,16 @@ Use the `HighlightSvelte` component for Svelte syntax highlighting.
|
|
|
488
582
|
<HighlightSvelte {code} />
|
|
489
583
|
```
|
|
490
584
|
|
|
585
|
+
Nested template declaration tags are also supported — including a second, shadowing `{const ...}` declared inside a nested element within the same `{#each}` block.
|
|
586
|
+
|
|
587
|
+
See the [kitchen-sink live demo](https://svhe.onrender.com/preview-svelte) for a fuller tour of Svelte highlighting across every theme.
|
|
588
|
+
|
|
491
589
|
## Auto-highlighting
|
|
492
590
|
|
|
493
|
-
The `HighlightAuto` component uses the [highlightAuto API](https://highlightjs.readthedocs.io/en/latest/api.html#highlightauto) and attempts to guess what grammar to use based on the provided `code`.
|
|
591
|
+
The `HighlightAuto` component uses the [highlightAuto API](https://highlightjs.readthedocs.io/en/latest/api.html#highlightauto) and attempts to guess what grammar to use based on the provided `code`. Its `on:highlight` event's `secondBest` field surfaces the runner-up candidate and its relevance, for showing detection confidence.
|
|
494
592
|
|
|
495
593
|
> [!WARNING]
|
|
496
|
-
>
|
|
594
|
+
> Mounting `HighlightAuto` statically imports all 279 shipped grammars, regardless of `languageNames`, so bundle size is unconditionally larger than a `Highlight` with a single named language. Specify a language if possible.
|
|
497
595
|
|
|
498
596
|
```svelte
|
|
499
597
|
<script>
|
|
@@ -512,7 +610,7 @@ The `HighlightAuto` component uses the [highlightAuto API](https://highlightjs.r
|
|
|
512
610
|
|
|
513
611
|
### Limiting Language Detection
|
|
514
612
|
|
|
515
|
-
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.
|
|
613
|
+
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 — it narrows the candidates scored during detection, but it does not reduce bundle size, since all shipped grammars are imported unconditionally (see the warning above). A grammar registered with `disableAutodetect: true` stays excluded from detection even when explicitly named in `languageNames`.
|
|
516
614
|
|
|
517
615
|
```svelte
|
|
518
616
|
<script>
|
|
@@ -583,6 +681,30 @@ The line number starts at `1`. Customize this via the `startingLineNumber` prop.
|
|
|
583
681
|
</Highlight>
|
|
584
682
|
```
|
|
585
683
|
|
|
684
|
+
### Windowed Lines
|
|
685
|
+
|
|
686
|
+
`LineNumbers` re-splits the entire `highlighted` string into lines on every update, which is wasteful once you're already rendering a window out of a much larger document. Pass a pre-split `lines` array instead -- the same per-line HTML shape `svelte-highlight/tokenized-document`'s `lineRange` (see [Large documents](#large-documents)) and `HighlightStream`'s incremental rendering already produce -- and set `lineCount` to the *total* document line count so the gutter is sized for the whole document instead of jittering as the window scrolls. `startingLineNumber` offsets the row numbers to match the window's position; `highlightedLines`/`lineStates` index relative to the `lines` array actually rendered, not the absolute document line.
|
|
687
|
+
|
|
688
|
+
```svelte
|
|
689
|
+
<script>
|
|
690
|
+
import { LineNumbers } from "svelte-highlight";
|
|
691
|
+
import { createTokenizedDocument } from "svelte-highlight/tokenized-document";
|
|
692
|
+
import typescript from "svelte-highlight/languages/typescript";
|
|
693
|
+
|
|
694
|
+
const doc = createTokenizedDocument({ language: typescript });
|
|
695
|
+
doc.setCode(bigFile);
|
|
696
|
+
|
|
697
|
+
const start = 50_000;
|
|
698
|
+
const end = 50_040;
|
|
699
|
+
</script>
|
|
700
|
+
|
|
701
|
+
<LineNumbers
|
|
702
|
+
lines={doc.lineRange(start, end)}
|
|
703
|
+
startingLineNumber={start + 1}
|
|
704
|
+
lineCount={doc.lineCount()}
|
|
705
|
+
/>
|
|
706
|
+
```
|
|
707
|
+
|
|
586
708
|
### Highlighted Lines
|
|
587
709
|
|
|
588
710
|
Specify the lines to highlight using the `highlightedLines` prop. Indices start at zero.
|
|
@@ -617,20 +739,49 @@ Use `--highlighted-background` to customize the background color of highlighted
|
|
|
617
739
|
</Highlight>
|
|
618
740
|
```
|
|
619
741
|
|
|
742
|
+
### Line States
|
|
743
|
+
|
|
744
|
+
`highlightedLines` only supports one visual treatment. Use `lineStates` for a per-line state map -- `"highlighted"` (same treatment as `highlightedLines`), `"focus"` (exempt from dimming, no background color), `"added"`, or `"removed"` -- so diff-style and meta-string-style decorations can share one primitive. Indices start at zero and are merged with `highlightedLines`, which is equivalent to setting `"highlighted"` here.
|
|
745
|
+
|
|
746
|
+
```svelte
|
|
747
|
+
<Highlight language={typescript} {code} let:highlighted>
|
|
748
|
+
<LineNumbers
|
|
749
|
+
{highlighted}
|
|
750
|
+
lineStates={{ 1: "added", 2: "removed", 4: "focus" }}
|
|
751
|
+
/>
|
|
752
|
+
</Highlight>
|
|
753
|
+
```
|
|
754
|
+
|
|
755
|
+
Use `--line-added-background` and `--line-removed-background` to customize the background colors.
|
|
756
|
+
|
|
757
|
+
```svelte
|
|
758
|
+
<Highlight language={typescript} {code} let:highlighted>
|
|
759
|
+
<LineNumbers
|
|
760
|
+
{highlighted}
|
|
761
|
+
lineStates={{ 1: "added", 2: "removed" }}
|
|
762
|
+
--line-added-background="rgba(0, 255, 0, 0.15)"
|
|
763
|
+
--line-removed-background="rgba(255, 0, 0, 0.15)"
|
|
764
|
+
/>
|
|
765
|
+
</Highlight>
|
|
766
|
+
```
|
|
767
|
+
|
|
620
768
|
### Custom Styles
|
|
621
769
|
|
|
622
770
|
Use `--style-props` to customize styles.
|
|
623
771
|
|
|
624
|
-
| Style prop
|
|
625
|
-
|
|
|
626
|
-
| --line-number-color
|
|
627
|
-
| --
|
|
628
|
-
| --
|
|
629
|
-
| --padding
|
|
630
|
-
| --padding-
|
|
631
|
-
| --
|
|
632
|
-
| --
|
|
633
|
-
| --
|
|
772
|
+
| Style prop | Description | Default value |
|
|
773
|
+
| :------------------------ | :------------------------------------------------------ | :-------------------------- |
|
|
774
|
+
| --line-number-color | Text color of the line numbers | `currentColor` |
|
|
775
|
+
| --line-number-digit-width | Width of a single gutter digit | `0.6em` |
|
|
776
|
+
| --border-color | Border color of the column of line numbers | `currentColor` |
|
|
777
|
+
| --padding | Fallback padding for `--padding-left` / `--padding-right` | `1em` |
|
|
778
|
+
| --padding-left | Left padding for `td` elements | `var(--padding, 1em)` |
|
|
779
|
+
| --padding-right | Right padding for `td` elements | `var(--padding, 1em)` |
|
|
780
|
+
| --highlighted-background | Background color of highlighted lines | `rgba(254, 241, 96, 0.2)` |
|
|
781
|
+
| --line-added-background | Background color of `lineStates` `"added"` lines | `rgba(46, 204, 113, 0.15)` |
|
|
782
|
+
| --line-removed-background | Background color of `lineStates` `"removed"` lines | `rgba(231, 76, 60, 0.15)` |
|
|
783
|
+
| --unhighlighted-opacity | Opacity of un-highlighted lines (focus mode) | `1` |
|
|
784
|
+
| --unhighlighted-filter | CSS filter for un-highlighted lines (focus mode) | `none` |
|
|
634
785
|
|
|
635
786
|
See [Styling with CSS variables](#styling-with-css-variables) for the full list, including container-level variables like `--border-radius`, `--width`, and `--overflow-x`.
|
|
636
787
|
|
|
@@ -639,6 +790,7 @@ See [Styling with CSS variables](#styling-with-css-variables) for the full list,
|
|
|
639
790
|
<LineNumbers
|
|
640
791
|
{highlighted}
|
|
641
792
|
--line-number-color="pink"
|
|
793
|
+
--line-number-digit-width="0.75em"
|
|
642
794
|
--border-color="rgba(255, 255, 255, 0.2)"
|
|
643
795
|
--padding-left={0}
|
|
644
796
|
--padding-right="3em"
|
|
@@ -649,6 +801,8 @@ See [Styling with CSS variables](#styling-with-css-variables) for the full list,
|
|
|
649
801
|
</Highlight>
|
|
650
802
|
```
|
|
651
803
|
|
|
804
|
+
The gutter's position and border use logical CSS properties (`inset-inline-start`/`inset-inline-end`), so it follows `dir="rtl"` without any extra configuration.
|
|
805
|
+
|
|
652
806
|
### Language Tag
|
|
653
807
|
|
|
654
808
|
When using a custom slot, forward `langtag` and `languageName` from `Highlight` to `LineNumbers`.
|
|
@@ -821,8 +975,11 @@ Use `bind:code` to keep your state in sync.
|
|
|
821
975
|
|
|
822
976
|
- **Enter** inserts a newline.
|
|
823
977
|
- **Tab** / **Shift+Tab** indent or dedent the selected lines (or insert one indent at the caret). Set the indent size with the `tabSize` prop (default `2`).
|
|
978
|
+
- **Escape** then **Tab**/**Shift+Tab** moves keyboard focus out of the editor instead of indenting, so the block never traps focus. Any other key clears this and restores normal Tab behavior.
|
|
824
979
|
- **Cmd/Ctrl+Z** undo and **Shift+Cmd/Ctrl+Z** (or **Ctrl+Y**) redo. Typing bursts collapse into a single undo step; cap the retained history with the `historyLimit` prop (default `200`).
|
|
825
980
|
|
|
981
|
+
Pasting and dragging content into the editor both insert plain text only, regardless of the source payload (rich text, HTML, etc.).
|
|
982
|
+
|
|
826
983
|
### Dispatched Events
|
|
827
984
|
|
|
828
985
|
`HighlightEditable` dispatches `change` (on every edit), `blur`, and `history` (whenever the undo/redo stack changes).
|
|
@@ -869,13 +1026,28 @@ Customize the focus outline with the `--outline-color`, `--outline-width`, and `
|
|
|
869
1026
|
/>
|
|
870
1027
|
```
|
|
871
1028
|
|
|
1029
|
+
### Read-only
|
|
1030
|
+
|
|
1031
|
+
Set `readonly` to keep highlighting, caret placement, and selection active while blocking edits (typing, paste, drag-and-drop, and Tab/Shift+Tab indent). The imperative API still works, so a consumer can toggle a document read-only without swapping components.
|
|
1032
|
+
|
|
1033
|
+
```svelte
|
|
1034
|
+
<script>
|
|
1035
|
+
let readonly = false;
|
|
1036
|
+
</script>
|
|
1037
|
+
|
|
1038
|
+
<HighlightEditable language={typescript} bind:code {readonly} />
|
|
1039
|
+
<button on:click={() => (readonly = !readonly)}>
|
|
1040
|
+
{readonly ? "Unlock" : "Lock"}
|
|
1041
|
+
</button>
|
|
1042
|
+
```
|
|
1043
|
+
|
|
872
1044
|
### Experimental: CSS Custom Highlight engine
|
|
873
1045
|
|
|
874
1046
|
`engine="css-highlights"` paints tokens with the [CSS Custom Highlight API](https://developer.mozilla.org/en-US/docs/Web/API/CSS_Custom_Highlight_API) (`CSS.highlights`, `::highlight()`) instead of wrapping them in `<span>`s. The editable `<code>` stays plain text (one `<span>` per line, reused from the default engine's line structure, but with no per-token spans inside), so a repaint never replaces the DOM the caret is sitting in.
|
|
875
1047
|
|
|
876
1048
|
Requires Chrome 105+, Safari 17.2+, or Firefox 140+. Where `CSS.highlights` is unavailable, `HighlightEditable` falls back to `engine="dom"` silently; check what actually ran with `editor.resolvedEngine()`.
|
|
877
1049
|
|
|
878
|
-
Pass `theme` (the same theme string you'd give `HighlightStyle`) to generate `::highlight()` rules from it. Only `color`/`background-color` convert —
|
|
1050
|
+
Pass `theme` (the same theme string you'd give `HighlightStyle`) to generate `::highlight()` rules from it. Only `color`/`background-color` convert, and only for single-class `.hljs-<scope>` rules — compound (`.hljs-title.class_`) and descendant-selector (`.hljs-meta .hljs-keyword`) scopes have no `::highlight()` equivalent and get **no color at all**, not just plain weight/style.
|
|
879
1051
|
|
|
880
1052
|
`theme` only covers token colors — you still need `HighlightStyle` (or an injected stylesheet) for the base `.hljs` layout rules (padding, overflow, background), exactly as with the default engine.
|
|
881
1053
|
|
|
@@ -893,6 +1065,25 @@ Pass `theme` (the same theme string you'd give `HighlightStyle`) to generate `::
|
|
|
893
1065
|
</HighlightStyle>
|
|
894
1066
|
```
|
|
895
1067
|
|
|
1068
|
+
### Adding a gutter
|
|
1069
|
+
|
|
1070
|
+
`HighlightEditable` has no slot and doesn't expose `highlighted`/`languageName`, so it can't be wrapped directly in `LineNumbers` the way a static `Highlight` block can. Mirror the same `code` in a second, read-only `Highlight` instance wrapped in `LineNumbers`, and position it alongside the editable block:
|
|
1071
|
+
|
|
1072
|
+
```svelte
|
|
1073
|
+
<script>
|
|
1074
|
+
import { Highlight, HighlightEditable, LineNumbers } from "svelte-highlight";
|
|
1075
|
+
import typescript from "svelte-highlight/languages/typescript";
|
|
1076
|
+
|
|
1077
|
+
let code = "const add = (a: number, b: number) => a + b";
|
|
1078
|
+
</script>
|
|
1079
|
+
|
|
1080
|
+
<HighlightEditable language={typescript} bind:code />
|
|
1081
|
+
|
|
1082
|
+
<Highlight language={typescript} {code} let:highlighted let:languageName>
|
|
1083
|
+
<LineNumbers {highlighted} {languageName} />
|
|
1084
|
+
</Highlight>
|
|
1085
|
+
```
|
|
1086
|
+
|
|
896
1087
|
## Language Targeting
|
|
897
1088
|
|
|
898
1089
|
All `Highlight` components apply a `data-language` attribute on the codeblock containing the language name.
|
|
@@ -907,10 +1098,16 @@ See [SUPPORTED_LANGUAGES.md](SUPPORTED_LANGUAGES.md) for a list of supported lan
|
|
|
907
1098
|
|
|
908
1099
|
## Language Tags
|
|
909
1100
|
|
|
1101
|
+
The language tag is one badge (`LangTag.svelte` + `langtag.css`) reached three ways: automatically, via `Highlight`/`HighlightAuto`/`HighlightSvelte`'s built-in fallback render when `langtag` is set; directly, via the standalone `LangTag` component; or via `LineNumbers`' own `langtag`/`languageName` props, which are not wired to a wrapping `Highlight` automatically and must be forwarded manually from slot props (see [Language Tag](#language-tag) under Line Numbers).
|
|
1102
|
+
|
|
910
1103
|
Set `langtag` to `true` to display the language name in the top right corner of the code block.
|
|
911
1104
|
|
|
912
1105
|
Customize the language tag `background`, `color`, and `border-radius` using style props.
|
|
913
1106
|
|
|
1107
|
+
Setting `langtag` opts a `<Highlight>` usage out of the [`svelte-highlight/static`](#static-mode) build-time transform, since static output can't pull in `langtag.css`.
|
|
1108
|
+
|
|
1109
|
+
If the highlighted output is empty (e.g. empty `code`, or code that highlights to an empty string), the badge and code block still render, but the code falls back to plain, unhighlighted text — the `hljs` class is still applied, there's just no syntax-highlighting markup inside it.
|
|
1110
|
+
|
|
914
1111
|
See the [Languages page](SUPPORTED_LANGUAGES.md) for a list of supported languages.
|
|
915
1112
|
|
|
916
1113
|
| Style prop | Description | Default value |
|
|
@@ -921,6 +1118,7 @@ See the [Languages page](SUPPORTED_LANGUAGES.md) for a list of supported languag
|
|
|
921
1118
|
| --langtag-color | Text color of the langtag | `inherit` |
|
|
922
1119
|
| --langtag-border-radius | Border radius of the langtag | `0` |
|
|
923
1120
|
| --langtag-padding | Padding of the langtag | `1em` |
|
|
1121
|
+
| --langtag-font-size | Font size of the langtag | `inherit` |
|
|
924
1122
|
|
|
925
1123
|
```svelte
|
|
926
1124
|
<script>
|
|
@@ -954,37 +1152,80 @@ The easiest way to author one is with `svelte-highlight/compat`'s `fromHighlight
|
|
|
954
1152
|
import { Highlight } from "svelte-highlight";
|
|
955
1153
|
import { fromHighlightJs } from "svelte-highlight/compat";
|
|
956
1154
|
|
|
957
|
-
function
|
|
1155
|
+
function defineDotenv(hljs) {
|
|
958
1156
|
return {
|
|
959
|
-
|
|
960
|
-
contains: [
|
|
1157
|
+
name: "dotenv",
|
|
1158
|
+
contains: [
|
|
1159
|
+
hljs.HASH_COMMENT_MODE,
|
|
1160
|
+
{ className: "keyword", begin: /^[ \t]*export(?=[ \t])/ },
|
|
1161
|
+
{ className: "attr", begin: /[A-Za-z_][A-Za-z0-9_]*(?=[ \t]*=)/ },
|
|
1162
|
+
{
|
|
1163
|
+
className: "string",
|
|
1164
|
+
variants: [
|
|
1165
|
+
{ begin: /"/, end: /"/, contains: [hljs.BACKSLASH_ESCAPE] },
|
|
1166
|
+
{ begin: /'/, end: /'/ },
|
|
1167
|
+
],
|
|
1168
|
+
},
|
|
1169
|
+
],
|
|
961
1170
|
};
|
|
962
1171
|
}
|
|
963
1172
|
|
|
964
|
-
const languagePromise = fromHighlightJs("
|
|
1173
|
+
const languagePromise = fromHighlightJs("dotenv", defineDotenv);
|
|
965
1174
|
</script>
|
|
966
1175
|
|
|
967
1176
|
{#await languagePromise then language}
|
|
968
|
-
<Highlight {language} code=
|
|
1177
|
+
<Highlight {language} code={'PORT=3000\n# comment'} />
|
|
969
1178
|
{/await}
|
|
970
1179
|
```
|
|
971
1180
|
|
|
972
1181
|
`fromHighlightJs` needs `highlight.js` itself, which svelte-highlight does not bundle — install it as your own dependency (`npm install highlight.js`). It's only imported the first time you call `fromHighlightJs`, so pages that never use it don't pay for it.
|
|
973
1182
|
|
|
1183
|
+
`fromHighlightJs` also accepts an optional third `source` argument (raw source text, e.g. via a bundler's `?raw` import) to recover array-membership `on:begin` guards the compiled callback alone can't expose, and the returned object carries a `warnings: string[]` field (empty when clean) so you can detect a degraded conversion without reading the console.
|
|
1184
|
+
|
|
1185
|
+
```ts
|
|
1186
|
+
const language = await fromHighlightJs("dotenv", defineDotenv, grammarSourceText);
|
|
1187
|
+
if (language.warnings.length > 0) {
|
|
1188
|
+
console.error("dotenv degraded:", language.warnings);
|
|
1189
|
+
}
|
|
1190
|
+
```
|
|
1191
|
+
|
|
974
1192
|
If you're using TypeScript, use the `LanguageType` interface to type the language.
|
|
975
1193
|
|
|
976
1194
|
```ts
|
|
977
1195
|
import type { LanguageType } from "svelte-highlight";
|
|
978
1196
|
import { fromHighlightJs } from "svelte-highlight/compat";
|
|
979
1197
|
|
|
980
|
-
const language: LanguageType<"
|
|
981
|
-
"
|
|
982
|
-
(hljs) => ({
|
|
1198
|
+
const language: LanguageType<"dotenv"> = await fromHighlightJs(
|
|
1199
|
+
"dotenv",
|
|
1200
|
+
(hljs) => ({
|
|
1201
|
+
name: "dotenv",
|
|
1202
|
+
contains: [
|
|
1203
|
+
hljs.HASH_COMMENT_MODE,
|
|
1204
|
+
{ className: "attr", begin: /[A-Za-z_][A-Za-z0-9_]*(?=[ \t]*=)/ },
|
|
1205
|
+
],
|
|
1206
|
+
}),
|
|
983
1207
|
);
|
|
984
1208
|
```
|
|
985
1209
|
|
|
986
1210
|
Building a package for others to install? Ship the converted grammar directly instead of calling `fromHighlightJs` at runtime — see [`scripts/convert-grammars.ts`](scripts/convert-grammars.ts) for the converter this package's own bundled languages go through.
|
|
987
1211
|
|
|
1212
|
+
### Conversion fidelity
|
|
1213
|
+
|
|
1214
|
+
`fromHighlightJs` and [`scripts/convert-grammars.ts`](scripts/convert-grammars.ts) (the pipeline behind every one of the ~244 bundled `svelte-highlight/languages/*` grammars) share the exact same converter, so a custom grammar goes through identical logic to every shipped one, not a lesser path.
|
|
1215
|
+
|
|
1216
|
+
Most hljs grammars are plain-JSON `contains`/`begin`/`end`/`className` rules, which convert as-is. A grammar can also use `on:begin`, `on:end`, or `__beforeBegin` callbacks for cases regexes alone can't express; the converter recognizes six specific shapes and turns them into declarative flags:
|
|
1217
|
+
|
|
1218
|
+
- An `on:begin` callback that copies the matched text so the closing delimiter must equal the opening one (heredocs).
|
|
1219
|
+
- An `on:begin` callback that only accepts a match at the very start of input (a shebang guard).
|
|
1220
|
+
- An `on:begin` callback that disambiguates an opening tag from a generic comparison (JSX).
|
|
1221
|
+
- An `on:begin` callback that checks the character immediately before the match (a letter-boundary guard).
|
|
1222
|
+
- An `on:begin` callback checking `SOME_SET.has(match[0])` against a module-level word list — recovered only when you also pass the grammar's own source text as `fromHighlightJs`'s third argument, since the compiled callback alone doesn't expose the backing array.
|
|
1223
|
+
- A `__beforeBegin` callback that rejects a match immediately following a `.` (hljs's `beginKeywords` dot-guard).
|
|
1224
|
+
|
|
1225
|
+
Any other `on:begin`/`on:end`/`__beforeBegin` body converts too, but with a `console.warn` and the rule's relevance forced to zero — it still matches, unconditionally, without skewing auto-detection. Check `language.warnings` (see above) to catch this without reading the console.
|
|
1226
|
+
|
|
1227
|
+
Upgrading a custom language written before 7.16? Before 7.16, a custom language was `{ name, register: (hljs) => modeObject }` passed synchronously straight to `<Highlight>`'s `language` prop. Since 7.16 replaced the highlight.js runtime with this package's own engine, `register` must be plain-JSON grammar IR instead, and `fromHighlightJs` (now async, requiring `{#await}`) is the replacement shown above.
|
|
1228
|
+
|
|
988
1229
|
## Custom Plugin
|
|
989
1230
|
|
|
990
1231
|
Third-party hljs language plugins work the same way: pass their `register(hljs)` export to `fromHighlightJs`.
|
|
@@ -1046,6 +1287,8 @@ In the example below, the `HighlightAuto` component and injected styles are dyna
|
|
|
1046
1287
|
/>
|
|
1047
1288
|
```
|
|
1048
1289
|
|
|
1290
|
+
Registering a grammar checks its canonical name, not an alias lookup, before skipping — so a grammar that aliases another (highlight.js's "ini" aliases "toml") can't make the real grammar look already-registered before it has actually loaded.
|
|
1291
|
+
|
|
1049
1292
|
### Loading a language by name
|
|
1050
1293
|
|
|
1051
1294
|
The example above imports a specific language as a static string, which lets the bundler split out only the grammars you reference. When the language is known only at **runtime** — a Markdown fence (` ```ts `), an API field, or a user-selected value — use the `loadLanguage` helper to import a grammar by name:
|
|
@@ -1071,22 +1314,28 @@ The example above imports a specific language as a static string, which lets the
|
|
|
1071
1314
|
{/await}
|
|
1072
1315
|
```
|
|
1073
1316
|
|
|
1074
|
-
`loadLanguage` accepts a [supported language name](SUPPORTED_LANGUAGES.md), dynamically imports its grammar, and resolves with the language object. It rejects with
|
|
1075
|
-
|
|
1076
|
-
> **Note:** Because the imported name is dynamic, the bundler cannot prune unused grammars and will emit a chunk for every language. Prefer a static `import` when the language is known ahead of time, and reach for `loadLanguage` only when it is not.
|
|
1077
|
-
|
|
1078
|
-
A practical case is rendering Markdown, where each fenced block declares its own language:
|
|
1317
|
+
`loadLanguage` accepts a [supported language name](SUPPORTED_LANGUAGES.md), dynamically imports its grammar, and resolves with the language object. It rejects with a `LanguageLoadError` for an unrecognized name, so handle the `{:catch}` block (or `.catch`) when the name comes from untrusted input. `LanguageLoadError` is importable from `svelte-highlight` for an `instanceof` check:
|
|
1079
1318
|
|
|
1080
1319
|
```js
|
|
1081
|
-
import {
|
|
1320
|
+
import { LanguageLoadError } from "svelte-highlight";
|
|
1082
1321
|
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1322
|
+
try {
|
|
1323
|
+
const grammar = await loadLanguage(name);
|
|
1324
|
+
} catch (error) {
|
|
1325
|
+
if (error instanceof LanguageLoadError) {
|
|
1326
|
+
// handle a missing/misspelled language name
|
|
1327
|
+
}
|
|
1087
1328
|
}
|
|
1088
1329
|
```
|
|
1089
1330
|
|
|
1331
|
+
Grammars with embedded sublanguages (`astro`, `svelte`, and others with a `dependencies` list) register their dependencies automatically — `Highlight`, `HighlightAuto`, and `HighlightSvelte` all call `ensureRegistered` on the language they're given, which registers the grammar and recurses through its dependencies.
|
|
1332
|
+
|
|
1333
|
+
`loadLanguage` does a fresh `import()` on every call and keeps no explicit cache, but it's safe to call repeatedly for the same name: module loaders dedupe dynamic imports by resolved specifier rather than re-fetching, so repeated calls resolve to the same cached module.
|
|
1334
|
+
|
|
1335
|
+
> **Note:** Because the imported name is dynamic, the bundler cannot prune unused grammars and will emit a chunk for every language — all 279 shipped grammars. Prefer a static `import` when the language is known ahead of time, and reach for `loadLanguage` only when it is not.
|
|
1336
|
+
|
|
1337
|
+
A practical case is rendering Markdown, where each fenced block declares its own language — see "[Rendering Markdown/MDX fences](#rendering-markdownmdx-fences)" below for a ready-made `highlightFence` helper built on top of `loadLanguage`.
|
|
1338
|
+
|
|
1090
1339
|
## Static mode
|
|
1091
1340
|
|
|
1092
1341
|
`svelte-highlight/static` is a Svelte preprocessor. At build time it replaces `<Highlight>` usages that have known `code` and `language` with pre-rendered `highlight.js` HTML, so the client never downloads `highlight.js` or that grammar module.
|
|
@@ -1125,7 +1374,7 @@ The static transform runs only when all of these are true:
|
|
|
1125
1374
|
- `language` is a plain identifier from a static `import` of `svelte-highlight/languages/*`.
|
|
1126
1375
|
- `code` is a string literal or a template literal with no `${...}` interpolation.
|
|
1127
1376
|
- The element has no slot content, spread props, or directives (`bind:`, `on:`, etc.).
|
|
1128
|
-
- `langtag
|
|
1377
|
+
- `langtag`, if set, is a bare flag or a static boolean literal (`langtag={true}`/`langtag={false}`) - not a variable or expression. Static output can't pull in `langtag.css` (that only happens when a runtime `LangTag` is in the bundle), so a truthy `langtag` renders the language badge as a plain inline-styled `<span>` instead, themed with the same `--langtag-*` custom properties `LangTag` reads - customization is limited to those variables, not `LangTag`'s slot content.
|
|
1129
1378
|
|
|
1130
1379
|
Dynamic `code` or `language`, `loadLanguage`, `HighlightAuto`, `HighlightSvelte`, and `HighlightEditable` keep the runtime component. No warning. That's intentional.
|
|
1131
1380
|
|
|
@@ -1139,7 +1388,102 @@ highlightStatic({
|
|
|
1139
1388
|
});
|
|
1140
1389
|
```
|
|
1141
1390
|
|
|
1142
|
-
|
|
1391
|
+
To measure how many `<Highlight>` usages a build actually converted to static markup, pass `onSummary`. It fires once per file with at least one shape-matched usage (files with none don't trigger it), so summing across calls gives a build-wide total:
|
|
1392
|
+
|
|
1393
|
+
```js
|
|
1394
|
+
let matched = 0;
|
|
1395
|
+
let succeeded = 0;
|
|
1396
|
+
|
|
1397
|
+
highlightStatic({
|
|
1398
|
+
onSummary(summary) {
|
|
1399
|
+
matched += summary.matched;
|
|
1400
|
+
succeeded += summary.succeeded;
|
|
1401
|
+
},
|
|
1402
|
+
});
|
|
1403
|
+
```
|
|
1404
|
+
|
|
1405
|
+
Scope is small on purpose. Extra props on `<Highlight>` don't carry over to the emitted `<pre>`. Unused `Highlight` and language imports are left in place; bundlers drop them (`sideEffects` in `package.json` is narrow enough).
|
|
1406
|
+
|
|
1407
|
+
### Rendering Markdown/MDX fences
|
|
1408
|
+
|
|
1409
|
+
`highlightStatic` only transforms literal `<Highlight>` usages in `.svelte` files. Markdown/MDX/mdsvex code fences never go through the Svelte compiler at all, so `svelte-highlight/fence` provides a separate, framework-agnostic building block: `parseMeta(meta)` and `highlightFence({ code, lang, meta })`, a plain async function with zero Svelte dependency.
|
|
1410
|
+
|
|
1411
|
+
```js
|
|
1412
|
+
import { highlightFence } from "svelte-highlight/fence";
|
|
1413
|
+
|
|
1414
|
+
const html = await highlightFence({
|
|
1415
|
+
code: 'const add = (a, b) => a + b;\nconst sub = (a, b) => a - b;\nexport { add, sub };',
|
|
1416
|
+
lang: "typescript",
|
|
1417
|
+
meta: '{1,3-5} title="app.ts"',
|
|
1418
|
+
});
|
|
1419
|
+
```
|
|
1420
|
+
|
|
1421
|
+
`lang` must be the grammar's canonical file name (see "[Loading a language by name](#loading-a-language-by-name)"); it rejects with `LanguageLoadError` for an unrecognized one. `meta` is the Expressive Code/Shiki-style vocabulary standardized on by tools like Astro, Starlight, and rehype-pretty-code: a bare `{1,3-5}` or `mark={1,3-5}` marks lines, `ins={...}`/`del={...}` mark insertions/deletions, `title="..."` sets a title, and `showLineNumbers` is a bare flag. The output wraps each line in `<span class="line" data-line-state="mark|ins|del">` (only when a state applies) inside a `<pre class="hljs" data-language="...">`, so a `mark`/`ins`/`del`-aware stylesheet can target `[data-line-state]` the same way it would target Expressive Code or Shiki output.
|
|
1422
|
+
|
|
1423
|
+
**mdsvex.** Wire `highlightFence` into `highlight.highlighter`, whose signature is `(code, lang, meta) => string | Promise<string>`:
|
|
1424
|
+
|
|
1425
|
+
```js
|
|
1426
|
+
// mdsvex.config.js
|
|
1427
|
+
import { highlightFence } from "svelte-highlight/fence";
|
|
1428
|
+
|
|
1429
|
+
/** @type {import("mdsvex").MdsvexOptions} */
|
|
1430
|
+
const config = {
|
|
1431
|
+
highlight: {
|
|
1432
|
+
highlighter: (code, lang, meta) => highlightFence({ code, lang, meta }),
|
|
1433
|
+
},
|
|
1434
|
+
};
|
|
1435
|
+
|
|
1436
|
+
export default config;
|
|
1437
|
+
```
|
|
1438
|
+
|
|
1439
|
+
**markdown-it.** Wire it into the `highlight` constructor option, whose signature is `(str, lang, attrs) => string` — markdown-it inserts the returned string verbatim (no further escaping), and `highlight` isn't allowed to be `async`, so pre-render fences you know about or fall back to a sync path for the rest:
|
|
1440
|
+
|
|
1441
|
+
```js
|
|
1442
|
+
import MarkdownIt from "markdown-it";
|
|
1443
|
+
import { highlightFence } from "svelte-highlight/fence";
|
|
1444
|
+
|
|
1445
|
+
const md = new MarkdownIt({
|
|
1446
|
+
highlight(str, lang, attrs) {
|
|
1447
|
+
// highlightFence is async; markdown-it's highlight isn't, so either
|
|
1448
|
+
// pre-highlight fences in a separate async pass before render() and
|
|
1449
|
+
// look the result up here, or fall back to escaped plain text.
|
|
1450
|
+
return md.utils.escapeHtml(str);
|
|
1451
|
+
},
|
|
1452
|
+
});
|
|
1453
|
+
```
|
|
1454
|
+
|
|
1455
|
+
**rehype.** `rehype`/`unist-util-visit` are the consumer's dependencies, not this package's. A rehype plugin walks the hast tree *after* `remark-rehype` has already converted fenced code to `<pre><code class="language-*">` — the fence's `meta` string isn't part of that hast by default, only `lang` (via the `language-*` class), so pass `meta` through only if an earlier remark step attached it (e.g. `node.data.hProperties["data-meta"] = mdastNode.meta`):
|
|
1456
|
+
|
|
1457
|
+
```js
|
|
1458
|
+
import { visit } from "unist-util-visit";
|
|
1459
|
+
import { highlightFence } from "svelte-highlight/fence";
|
|
1460
|
+
|
|
1461
|
+
function rehypeHighlightFence() {
|
|
1462
|
+
return async (tree) => {
|
|
1463
|
+
const nodes = [];
|
|
1464
|
+
visit(tree, "element", (node, index, parent) => {
|
|
1465
|
+
if (node.tagName !== "pre" || parent === undefined || index === undefined) return;
|
|
1466
|
+
const code = node.children.find((child) => child.tagName === "code");
|
|
1467
|
+
if (code) nodes.push({ node, index, parent, code });
|
|
1468
|
+
});
|
|
1469
|
+
|
|
1470
|
+
for (const { node, index, parent, code } of nodes) {
|
|
1471
|
+
const lang = code.properties?.className
|
|
1472
|
+
?.map(String)
|
|
1473
|
+
.find((c) => c.startsWith("language-"))
|
|
1474
|
+
?.slice("language-".length);
|
|
1475
|
+
if (!lang) continue;
|
|
1476
|
+
|
|
1477
|
+
const html = await highlightFence({
|
|
1478
|
+
code: code.children.map((c) => (c.type === "text" ? c.value : "")).join(""),
|
|
1479
|
+
lang,
|
|
1480
|
+
meta: code.properties?.["data-meta"],
|
|
1481
|
+
});
|
|
1482
|
+
parent.children[index] = { type: "raw", value: html };
|
|
1483
|
+
}
|
|
1484
|
+
};
|
|
1485
|
+
}
|
|
1486
|
+
```
|
|
1143
1487
|
|
|
1144
1488
|
## Action
|
|
1145
1489
|
|
|
@@ -1347,6 +1691,29 @@ Control the pacing curve with `easing`: a function mapping elapsed-time fraction
|
|
|
1347
1691
|
|
|
1348
1692
|
Named curves: `linear` (default), `easeInQuad`/`easeOutQuad`/`easeInOutQuad`, `easeInCubic`/`easeOutCubic`/`easeInOutCubic`, `easeInSine`/`easeOutSine`/`easeInOutSine`.
|
|
1349
1693
|
|
|
1694
|
+
Set `speed={0}` to reveal all content on the very first frame -- a documented "skip typing" escape hatch, useful for a "skip" button or for finishing an off-screen instance instantly.
|
|
1695
|
+
|
|
1696
|
+
By default `granularity="char"` reveals one character at a time. Set `granularity="word"` to reveal a full word per step instead -- a ChatGPT-style token-by-token reveal. Total typing duration and `easing` are unaffected either way; only which character counts `revealed` may land on changes.
|
|
1697
|
+
|
|
1698
|
+
```svelte
|
|
1699
|
+
<Highlight language={typescript} {code} let:highlighted>
|
|
1700
|
+
<Typewriter {highlighted} granularity="word" />
|
|
1701
|
+
</Highlight>
|
|
1702
|
+
```
|
|
1703
|
+
|
|
1704
|
+
Fire `on:progress` for a progress bar or "X% typed" indicator -- it dispatches `{ revealed, total }` (visible-character counts) whenever `revealed` advances. `revealed` and `total` are also exposed for `bind:revealed`/`bind:total`, though both are read-only in practice: the component overwrites them every frame.
|
|
1705
|
+
|
|
1706
|
+
```svelte
|
|
1707
|
+
<Highlight language={typescript} {code} let:highlighted>
|
|
1708
|
+
<Typewriter
|
|
1709
|
+
{highlighted}
|
|
1710
|
+
bind:revealed
|
|
1711
|
+
bind:total
|
|
1712
|
+
on:progress={(e) => console.log(`${e.detail.revealed}/${e.detail.total}`)}
|
|
1713
|
+
/>
|
|
1714
|
+
</Highlight>
|
|
1715
|
+
```
|
|
1716
|
+
|
|
1350
1717
|
`Typewriter` doesn't gate itself on `prefers-reduced-motion` -- if you want to honor it, check `matchMedia("(prefers-reduced-motion: reduce)")` yourself and skip rendering `Typewriter` (or set a very low `speed`). Customize the caret with `--caret-width`, `--caret-height`, `--caret-gap`, `--caret-color`, and `--caret-blink`.
|
|
1351
1718
|
|
|
1352
1719
|
|
|
@@ -1386,8 +1753,12 @@ Append to `code` as chunks come in; set `done` once the stream ends.
|
|
|
1386
1753
|
|
|
1387
1754
|
Multiple chunks appended within the same animation frame coalesce into a single highlight pass. Already-rendered lines are diffed and left untouched in the DOM; only lines whose content actually changed are repainted, so a fast-scrolling response only touches its changed suffix (typically the last line). A multi-line construct left open mid-stream -- an unterminated template literal or block comment -- re-tokenizes the lines it spans once the closing delimiter arrives, with no special-casing needed: it falls out of re-highlighting the full buffer on every update.
|
|
1388
1755
|
|
|
1756
|
+
`code` doesn't have to only grow by appending -- an edit to already-streamed text (an LLM regenerating an earlier paragraph, say) is handled incrementally too, via `StreamSession#replace()` under the hood, instead of discarding the session and re-tokenizing the whole buffer from scratch.
|
|
1757
|
+
|
|
1389
1758
|
A blinking caret marks the end of output while `!done`; setting `done` hides it and performs one final full highlight, so the finished output matches what `Highlight` would render for the same code. `on:done` fires right after that final highlight. Customize the caret with the same `--caret-width`, `--caret-height`, `--caret-gap`, `--caret-color`, and `--caret-blink` variables as `Typewriter`.
|
|
1390
1759
|
|
|
1760
|
+
A blinking caret is a purely visual cue, so the root element also carries `aria-busy` while `!done`, and a visually-hidden, polite live region announces `doneText` (default `"Code finished streaming"`) once `done` flips to `true` -- screen reader users get the same "still streaming" / "finished" signal sighted users get from the caret. Set `doneText` to `""` to disable the announcement.
|
|
1761
|
+
|
|
1391
1762
|
Set `autoScroll` to keep the container pinned to the bottom as output grows -- it stops auto-scrolling as soon as you scroll up, and resumes once you scroll back to the bottom.
|
|
1392
1763
|
|
|
1393
1764
|
```svelte
|
|
@@ -1400,7 +1771,7 @@ Per-chunk work is O(tail), not O(stream length so far): finished output is seale
|
|
|
1400
1771
|
<HighlightStream language={typescript} {code} {done} virtualize style="height: 20em;" />
|
|
1401
1772
|
```
|
|
1402
1773
|
|
|
1403
|
-
`virtualize` renders only the lines within the scrolled viewport (plus `overscan`), the same windowing `HighlightVirtual` does for static documents -- a stream that runs to tens of thousands of lines still costs a couple dozen DOM nodes. It swaps the sealed-chunk session for `TokenizedDocument` (see [Large documents](#large-documents) below), so output always reflects the streaming (non-canonicalized) parse, even once `done` -- unlike the default mode, which upgrades to a canonical final render. `on:highlight` isn't dispatched in this mode, since materializing the full HTML on every repaint would defeat the point of windowing; `on:done`, the caret, and `autoScroll` all keep working.
|
|
1774
|
+
`virtualize` renders only the lines within the scrolled viewport (plus `overscan`), the same windowing `HighlightVirtual` does for static documents -- a stream that runs to tens of thousands of lines still costs a couple dozen DOM nodes. It swaps the sealed-chunk session for `TokenizedDocument` (see [Large documents](#large-documents) below), so output always reflects the streaming (non-canonicalized) parse, even once `done` -- unlike the default mode, which upgrades to a canonical final render. `on:highlight` isn't dispatched in this mode, since materializing the full HTML on every repaint would defeat the point of windowing; `on:done`, the caret, and `autoScroll` all keep working. `on:windowchange` fires with `{ start, end, lineCount }` whenever the rendered window moves, so you can show something like "lines *N*-*M* of *T*" without counting DOM nodes yourself. Row math assumes one line per fixed-height row, so `virtualize` can't wrap lines -- it always renders with `white-space: pre`, overriding any `white-space` you pass through `$$restProps`.
|
|
1404
1775
|
|
|
1405
1776
|
## Large documents
|
|
1406
1777
|
|
|
@@ -1420,7 +1791,9 @@ Per-chunk work is O(tail), not O(stream length so far): finished output is seale
|
|
|
1420
1791
|
<HighlightVirtual language={json} code={hugeLogDump} style="height: 480px" />
|
|
1421
1792
|
```
|
|
1422
1793
|
|
|
1423
|
-
The rendered `<pre>` is the scroll container itself -- size it with `style`/`class`/`$$restProps`, same as `Highlight
|
|
1794
|
+
The rendered `<pre>` is the scroll container itself -- size it with `style`/`class`/`$$restProps`, same as `Highlight`, but `white-space` can't be overridden this way: it's pinned to `pre` because the windowing math depends on a uniform line height. Content doesn't wrap (uniform line height is a v1 constraint, measured once from a rendered probe line). `overscan` (default `12`) controls how many extra lines render above/below the viewport; `checkpointInterval` (default `100`) controls how often the engine snapshots its parse state, trading a little memory for cheaper random access. Concretely, memory scales with `document lines / checkpointInterval` retained checkpoints, each holding a full engine snapshot plus open-scope/pending-HTML state -- and checkpoints are never evicted: they're retained for the entire lifetime of the `TokenizedDocument` instance, across any number of `append()` calls, until a `setCode()` call with unrelated content triggers a full reset. This is fine for the target "huge static document" use case, since checkpoints are bounded by that one document's size, but worth knowing for a long-lived instance that's repeatedly `setCode()`-reset with genuinely new documents rather than recreated. A consumer worried about retained memory can call `doc.checkpointCount()` directly rather than estimating it from `lineCount()`/`checkpointInterval`. Server-rendered output is the full document as plain escaped text (predictable cost for huge documents); the windowed, highlighted view takes over after hydration. In practice this means every page load flashes from unstyled monochrome text to highlighted, windowed content right after hydration, with no fade -- unlike `HighlightStream`'s default (non-`virtualize`) mode, which SSRs already-highlighted HTML. Nothing here requires a component change to soften today: since the container already needs an explicit size (`style`/`class`/`$$restProps`, above), reserving that same `min-height`/`height` up front prevents layout shift, and a CSS transition keyed off a `data-hydrated` attribute or class toggle you set yourself -- e.g. in `onMount` on a wrapping element -- can fade the flash instead of leaving it instant.
|
|
1795
|
+
|
|
1796
|
+
`on:windowchange` fires with `{ start, end, lineCount }` whenever the rendered window moves, so you can show something like "lines *N*-*M* of *T*" without counting DOM nodes yourself. `bind:this`, then call `scrollToLine(line)` to scroll a given line into view -- useful for a "jump to line" control -- without guessing at the line height yourself.
|
|
1424
1797
|
|
|
1425
1798
|
For custom virtualization, servers, or tests, `svelte-highlight/tokenized-document` exposes the same windowing primitive headlessly:
|
|
1426
1799
|
|
|
@@ -1435,7 +1808,54 @@ doc.lineRange(50_000, 50_040); // 40 highlighted lines in O(window + interval)
|
|
|
1435
1808
|
doc.append(moreCode); // streaming growth, no re-tokenization
|
|
1436
1809
|
```
|
|
1437
1810
|
|
|
1438
|
-
`
|
|
1811
|
+
`Typewriter`'s tokenizer is available the same way, for a custom reveal UI or non-DOM use: `svelte-highlight/typewriter-units` exposes `tokenizeTypewriter`, `buildUnitMarkup`, `createTypewriterSplitter`, and `computeWordBoundaries` headlessly.
|
|
1812
|
+
|
|
1813
|
+
```js
|
|
1814
|
+
import {
|
|
1815
|
+
computeWordBoundaries,
|
|
1816
|
+
tokenizeTypewriter,
|
|
1817
|
+
} from "svelte-highlight/typewriter-units";
|
|
1818
|
+
|
|
1819
|
+
const units = tokenizeTypewriter(highlighted);
|
|
1820
|
+
const wordBoundaries = computeWordBoundaries(units); // for word-by-word reveal
|
|
1821
|
+
```
|
|
1822
|
+
|
|
1823
|
+
`lineRange` tokenizes lazily and caches the most recently resolved window, so scrolling through even a huge document only ever pays for the lines actually requested. Its output matches `HighlightStream`'s live (non-canonicalized) parse: constructs needing multi-line lookahead across a window's edge can render slightly differently than `registry.highlight()`'s canonical output, the same tradeoff streaming already makes. `TokenizedDocument` doesn't support mid-document edits -- `append` and full `setCode` resets only. For a bounded, editable document (not a windowed/virtualized one), `HighlightEditable` solves mid-document editing, built on its own checkpoint-resume re-tokenizer (`src/incremental-tokenize.js`, not itself a public export). The two aren't unified today -- there's no single primitive yet for a document that's both editable and virtualized.
|
|
1824
|
+
|
|
1825
|
+
### Without virtualization
|
|
1826
|
+
|
|
1827
|
+
For documents in the low thousands to tens of thousands of lines (roughly 2,000-20,000), `HighlightVirtual`'s hard constraints -- no wrapping, an SSR-to-hydration flash, a fixed-height v1 container -- may not be worth taking on. The CSS [`content-visibility: auto`](https://developer.mozilla.org/en-US/docs/Web/CSS/content-visibility) property gets you a native-scrolling, cheap-to-render alternative built entirely from already-public APIs, at the cost of the DOM-node count `HighlightVirtual` avoids:
|
|
1828
|
+
|
|
1829
|
+
```svelte
|
|
1830
|
+
<script>
|
|
1831
|
+
import { createRegistry, registerAll, tokenLines } from "svelte-highlight/engine";
|
|
1832
|
+
import typescript from "svelte-highlight/languages/typescript";
|
|
1833
|
+
|
|
1834
|
+
const registry = createRegistry();
|
|
1835
|
+
registerAll(registry, typescript);
|
|
1836
|
+
|
|
1837
|
+
export let code;
|
|
1838
|
+
const { events } = registry.highlight(code, { language: "typescript" });
|
|
1839
|
+
const lines = tokenLines(events); // [[{ text, scopes }, …], …]
|
|
1840
|
+
|
|
1841
|
+
function scopeClass(scope) {
|
|
1842
|
+
return scope
|
|
1843
|
+
.split(".")
|
|
1844
|
+
.map((piece) => `hljs-${piece}`)
|
|
1845
|
+
.join(" ");
|
|
1846
|
+
}
|
|
1847
|
+
</script>
|
|
1848
|
+
|
|
1849
|
+
<div class="hljs" style="content-visibility: auto; contain-intrinsic-size: auto 1000px;">
|
|
1850
|
+
{#each lines as line}
|
|
1851
|
+
<div style="white-space: pre; content-visibility: auto; contain-intrinsic-size: auto 20px;">
|
|
1852
|
+
{#each line as token}<span class={token.scopes.map(scopeClass).join(" ")}>{token.text}</span>{/each}
|
|
1853
|
+
</div>
|
|
1854
|
+
{/each}
|
|
1855
|
+
</div>
|
|
1856
|
+
```
|
|
1857
|
+
|
|
1858
|
+
Each line is its own block-level `<div>`, not a row in a `<table>`/`<tr>` (the way `LineNumbers` renders) -- `content-visibility` doesn't apply to table-internal display types, so off-screen table rows never get the skip. Off-screen `<div>` lines do: the browser skips layout/paint/style for them, using `contain-intrinsic-size` as a placeholder size until they scroll near the viewport. Unlike `HighlightVirtual`, this is a progressive enhancement, not a hard requirement -- browsers without `content-visibility` support just render every line normally, and you get native text selection, find-in-page, and line wrapping for free (drop the `white-space: pre` on each line's `<div>` to allow it).
|
|
1439
1859
|
|
|
1440
1860
|
## Terminal Output
|
|
1441
1861
|
|
|
@@ -1452,7 +1872,7 @@ Use `AnsiOutput` to render terminal output that still contains ANSI [SGR](https:
|
|
|
1452
1872
|
<AnsiOutput {text} />
|
|
1453
1873
|
```
|
|
1454
1874
|
|
|
1455
|
-
Malformed or unsupported escape sequences are dropped. Nothing throws.
|
|
1875
|
+
Malformed or unsupported escape sequences are dropped. Nothing throws. OSC 8 hyperlinks only render as links for `http:`, `https:`, and `mailto:` URIs; any other scheme renders as plain text. `parseAnsi` is one-shot and drops a trailing unterminated sequence, so for streamed output accumulate the full text and re-parse it rather than calling it once per chunk.
|
|
1456
1876
|
|
|
1457
1877
|
### Theming the palette
|
|
1458
1878
|
|
|
@@ -1477,6 +1897,14 @@ With `autoContrast` on (the default), spans that set a background get a readable
|
|
|
1477
1897
|
<AnsiOutput {text} autoContrast={false} />
|
|
1478
1898
|
```
|
|
1479
1899
|
|
|
1900
|
+
### Wrapping long lines
|
|
1901
|
+
|
|
1902
|
+
`AnsiOutput` never wraps by default -- long lines scroll horizontally. Set `wrap` to wrap them instead:
|
|
1903
|
+
|
|
1904
|
+
```svelte
|
|
1905
|
+
<AnsiOutput {text} wrap />
|
|
1906
|
+
```
|
|
1907
|
+
|
|
1480
1908
|
### Pairing with `CodeWindow`
|
|
1481
1909
|
|
|
1482
1910
|
Put `AnsiOutput` inside `CodeWindow variant="terminal"` for the prompt and title bar:
|
|
@@ -1540,6 +1968,12 @@ Arrow keys move between tabs; `Home` and `End` jump to the first and last. The m
|
|
|
1540
1968
|
</FileTabs>
|
|
1541
1969
|
```
|
|
1542
1970
|
|
|
1971
|
+
`active` is reconciled whenever `files` changes: an unknown or stale value (including a `bind:active` set before `files` loads) falls back to `files[0]`; removing the active file selects its former neighbor (same index, clamped to the new length), like closing a tab in an editor; an empty `files` array sets `active` to `undefined` and the tab panel omits `aria-labelledby`. `on:change` fires once whenever this reconciliation actually changes `active`.
|
|
1972
|
+
|
|
1973
|
+
When the tab strip overflows, its overflowing edge fades to signal there's more to scroll to; changing `active` (by click, keyboard, or `bind:active`) scrolls that tab into view.
|
|
1974
|
+
|
|
1975
|
+
The active tab's `--tab-active-color` and `--tab-active-background` are resolved from the highlighted code's computed style after mount, so they render as `inherit`/`transparent` on first paint; for an SSR-critical, above-the-fold tab strip, set `--tab-active-background` and `--tab-active-color` yourself to avoid a flash before hydration.
|
|
1976
|
+
|
|
1543
1977
|
## Component API
|
|
1544
1978
|
|
|
1545
1979
|
### `Highlight`
|
|
@@ -1551,12 +1985,13 @@ Arrow keys move between tabs; `Home` and `End` jump to the first and last. The m
|
|
|
1551
1985
|
| code | `any` | N/A (required) |
|
|
1552
1986
|
| language | { name: `string`; register: `object` } | N/A (required) |
|
|
1553
1987
|
| langtag | `boolean` | `false` |
|
|
1988
|
+
| wrap | `boolean` | `false` |
|
|
1554
1989
|
|
|
1555
1990
|
`$$restProps` are forwarded to the top-level `pre` element.
|
|
1556
1991
|
|
|
1557
1992
|
#### Dispatched Events
|
|
1558
1993
|
|
|
1559
|
-
- **on:highlight**: fired after `code` is highlighted
|
|
1994
|
+
- **on:highlight**: fired after `code` is highlighted, once per change (not on unrelated re-renders), including when the result is empty (empty `code`)
|
|
1560
1995
|
|
|
1561
1996
|
```svelte
|
|
1562
1997
|
<Highlight
|
|
@@ -1579,19 +2014,37 @@ Arrow keys move between tabs; `Home` and `End` jump to the first and last. The m
|
|
|
1579
2014
|
/>
|
|
1580
2015
|
```
|
|
1581
2016
|
|
|
2017
|
+
### `HighlightStyle`
|
|
2018
|
+
|
|
2019
|
+
#### Props
|
|
2020
|
+
|
|
2021
|
+
| Name | Type | Default value |
|
|
2022
|
+
| :--------- | :---------------------- | :------------------------ |
|
|
2023
|
+
| theme | `string \| ThemePalette` | N/A |
|
|
2024
|
+
| light | `string \| ThemePalette` | N/A |
|
|
2025
|
+
| dark | `string \| ThemePalette` | N/A |
|
|
2026
|
+
| mode | `"auto" \| "light" \| "dark" \| string` | `"auto"` |
|
|
2027
|
+
| scopeClass | `string` | hash of `theme` |
|
|
2028
|
+
| nonce | `string` | N/A |
|
|
2029
|
+
|
|
2030
|
+
The default slot exposes `{ scopeClass }`. `$$restProps` are forwarded to the top-level `div` element.
|
|
2031
|
+
|
|
1582
2032
|
### `LineNumbers`
|
|
1583
2033
|
|
|
1584
2034
|
#### Props
|
|
1585
2035
|
|
|
1586
|
-
| Name | Type
|
|
1587
|
-
| :----------------- |
|
|
1588
|
-
| highlighted | `string`
|
|
1589
|
-
|
|
|
1590
|
-
|
|
|
1591
|
-
|
|
|
1592
|
-
|
|
|
1593
|
-
|
|
|
1594
|
-
|
|
|
2036
|
+
| Name | Type | Default value |
|
|
2037
|
+
| :----------------- | :---------------------------------------------------------- | :----------------------------------- |
|
|
2038
|
+
| highlighted | `string` | N/A (required unless `lines` is set) |
|
|
2039
|
+
| lines | `string[]` | `undefined` |
|
|
2040
|
+
| lineCount | `number` | `undefined` |
|
|
2041
|
+
| hideBorder | `boolean` | `false` |
|
|
2042
|
+
| wrapLines | `boolean` | `false` |
|
|
2043
|
+
| startingLineNumber | `number` | `1` |
|
|
2044
|
+
| highlightedLines | `number[]` | `[]` |
|
|
2045
|
+
| lineStates | `Record<number, "highlighted" \| "focus" \| "added" \| "removed">` | `{}` |
|
|
2046
|
+
| langtag | `boolean` | `false` |
|
|
2047
|
+
| languageName | `string` | `"plaintext"` |
|
|
1595
2048
|
|
|
1596
2049
|
`$$restProps` are forwarded to the top-level `div` element.
|
|
1597
2050
|
|
|
@@ -1642,6 +2095,7 @@ Arrow keys move between tabs; `Home` and `End` jump to the first and last. The m
|
|
|
1642
2095
|
| :----------- | :-------- | :------------- |
|
|
1643
2096
|
| text | `string` | N/A (required) |
|
|
1644
2097
|
| autoContrast | `boolean` | `true` |
|
|
2098
|
+
| wrap | `boolean` | `false` |
|
|
1645
2099
|
|
|
1646
2100
|
`$$restProps` are forwarded to the top-level `pre` element.
|
|
1647
2101
|
|
|
@@ -1653,12 +2107,13 @@ Arrow keys move between tabs; `Home` and `End` jump to the first and last. The m
|
|
|
1653
2107
|
| :------ | :-------- | :------------- |
|
|
1654
2108
|
| code | `any` | N/A (required) |
|
|
1655
2109
|
| langtag | `boolean` | `false` |
|
|
2110
|
+
| wrap | `boolean` | `false` |
|
|
1656
2111
|
|
|
1657
2112
|
`$$restProps` are forwarded to the top-level `pre` element.
|
|
1658
2113
|
|
|
1659
2114
|
#### Dispatched Events
|
|
1660
2115
|
|
|
1661
|
-
- **on:highlight**: fired after `code` is highlighted
|
|
2116
|
+
- **on:highlight**: fired after `code` is highlighted, once per change (not on unrelated re-renders), including when the result is empty (empty `code`)
|
|
1662
2117
|
|
|
1663
2118
|
```svelte
|
|
1664
2119
|
<HighlightSvelte
|
|
@@ -1680,11 +2135,12 @@ Arrow keys move between tabs; `Home` and `End` jump to the first and last. The m
|
|
|
1680
2135
|
|
|
1681
2136
|
#### Props
|
|
1682
2137
|
|
|
1683
|
-
| Name
|
|
1684
|
-
|
|
|
1685
|
-
| code
|
|
1686
|
-
|
|
|
1687
|
-
| langtag
|
|
2138
|
+
| Name | Type | Default value |
|
|
2139
|
+
| :------------ | :--------------- | :------------- |
|
|
2140
|
+
| code | `any` | N/A (required) |
|
|
2141
|
+
| languageNames | `LanguageName[]` | `undefined` |
|
|
2142
|
+
| langtag | `boolean` | `false` |
|
|
2143
|
+
| wrap | `boolean` | `false` |
|
|
1688
2144
|
|
|
1689
2145
|
`$$restProps` are forwarded to the top-level `pre` element.
|
|
1690
2146
|
|
|
@@ -1696,7 +2152,7 @@ import type { LanguageName } from "svelte-highlight";
|
|
|
1696
2152
|
|
|
1697
2153
|
#### Dispatched Events
|
|
1698
2154
|
|
|
1699
|
-
- **on:highlight**: fired after `code` is highlighted
|
|
2155
|
+
- **on:highlight**: fired after `code` is highlighted, once per change (not on unrelated re-renders), including when the result is empty (empty `code`, or no candidate language matches)
|
|
1700
2156
|
|
|
1701
2157
|
```svelte
|
|
1702
2158
|
<HighlightAuto
|
|
@@ -1716,6 +2172,13 @@ import type { LanguageName } from "svelte-highlight";
|
|
|
1716
2172
|
|
|
1717
2173
|
/** The scope-event stream behind `highlighted`. See "Headless usage" below. */
|
|
1718
2174
|
console.log(e.detail.events);
|
|
2175
|
+
|
|
2176
|
+
/**
|
|
2177
|
+
* The runner-up candidate and its relevance, for surfacing detection
|
|
2178
|
+
* confidence. `undefined` when no other candidate scored above zero.
|
|
2179
|
+
* @example { language: "typescript", relevance: 6 }
|
|
2180
|
+
*/
|
|
2181
|
+
console.log(e.detail.secondBest);
|
|
1719
2182
|
}}
|
|
1720
2183
|
/>
|
|
1721
2184
|
```
|
|
@@ -1730,6 +2193,7 @@ import type { LanguageName } from "svelte-highlight";
|
|
|
1730
2193
|
| language | { name: `string`; register: `object` } | N/A (required) |
|
|
1731
2194
|
| tabSize | `number` | `2` |
|
|
1732
2195
|
| historyLimit | `number` | `200` |
|
|
2196
|
+
| readonly | `boolean` | `false` |
|
|
1733
2197
|
|
|
1734
2198
|
`$$restProps` are forwarded to the top-level `pre` element.
|
|
1735
2199
|
|
|
@@ -1768,13 +2232,15 @@ Use `bind:this`, then call `undo()`, `redo()`, `focus()`, `selectAll()`, `insert
|
|
|
1768
2232
|
| virtualize | `boolean` | `false` |
|
|
1769
2233
|
| overscan | `number` | `12` |
|
|
1770
2234
|
| checkpointInterval | `number` | `100` |
|
|
2235
|
+
| doneText | `string` | `"Code finished streaming"` |
|
|
1771
2236
|
|
|
1772
|
-
`$$restProps` are forwarded to the top-level `pre` element. `overscan` and `checkpointInterval` only apply when `virtualize` is set.
|
|
2237
|
+
`$$restProps` are forwarded to the top-level `pre` element. `overscan` and `checkpointInterval` only apply when `virtualize` is set. `doneText` is announced by a visually-hidden live region once `done` becomes `true`; set it to `""` to disable the announcement.
|
|
1773
2238
|
|
|
1774
2239
|
#### Dispatched Events
|
|
1775
2240
|
|
|
1776
2241
|
- **on:highlight**: fired after each highlight pass, with `{ highlighted }` -- not dispatched when `virtualize` is set
|
|
1777
2242
|
- **on:done**: fired after the final full highlight once `done` is set
|
|
2243
|
+
- **on:windowchange**: fired with `{ start, end, lineCount }` whenever the rendered window moves -- only dispatched when `virtualize` is set
|
|
1778
2244
|
|
|
1779
2245
|
```svelte
|
|
1780
2246
|
<HighlightStream
|
|
@@ -1797,7 +2263,15 @@ Use `bind:this`, then call `undo()`, `redo()`, `focus()`, `selectAll()`, `insert
|
|
|
1797
2263
|
| overscan | `number` | `12` |
|
|
1798
2264
|
| checkpointInterval | `number` | `100` |
|
|
1799
2265
|
|
|
1800
|
-
`$$restProps` are forwarded to the top-level `pre` element (the scroll container -- size it with `style`/`class`).
|
|
2266
|
+
`$$restProps` are forwarded to the top-level `pre` element (the scroll container -- size it with `style`/`class`, but `white-space` is pinned to `pre` and can't be overridden this way).
|
|
2267
|
+
|
|
2268
|
+
#### Methods
|
|
2269
|
+
|
|
2270
|
+
Use `bind:this`, then call `scrollToLine(line)`.
|
|
2271
|
+
|
|
2272
|
+
#### Dispatched Events
|
|
2273
|
+
|
|
2274
|
+
- **on:windowchange**: fired whenever the rendered window changes, with `{ start, end, lineCount }`
|
|
1801
2275
|
|
|
1802
2276
|
```svelte
|
|
1803
2277
|
<HighlightVirtual language={json} code={hugeLogDump} style="height: 480px" />
|
|
@@ -1814,7 +2288,7 @@ See [Large documents](#large-documents) above.
|
|
|
1814
2288
|
| files | `string[]` | N/A (required) |
|
|
1815
2289
|
| active | `string` | `files[0]` |
|
|
1816
2290
|
|
|
1817
|
-
`$$restProps` are forwarded to the top-level `div` element. `active` supports `bind:active`.
|
|
2291
|
+
`$$restProps` are forwarded to the top-level `div` element. `active` supports `bind:active` and is reconciled against `files`: an unknown value falls back to `files[0]`, removing the active file selects its former neighbor, and an empty `files` array sets `active` to `undefined`.
|
|
1818
2292
|
|
|
1819
2293
|
#### Dispatched Events
|
|
1820
2294
|
|
|
@@ -1836,12 +2310,16 @@ See [Large documents](#large-documents) above.
|
|
|
1836
2310
|
| speed | `number` | `30` |
|
|
1837
2311
|
| play | `boolean` | `true` |
|
|
1838
2312
|
| easing | `(t: number) => number` | `linear` |
|
|
2313
|
+
| granularity | `"char" \| "word"` | `"char"` |
|
|
2314
|
+
| revealed | `number` | `0` |
|
|
2315
|
+
| total | `number` | `0` |
|
|
1839
2316
|
|
|
1840
|
-
`$$restProps` are forwarded to the top-level `pre` element.
|
|
2317
|
+
`$$restProps` are forwarded to the top-level `pre` element. `revealed`/`total` are read-only in practice (overwritten every frame) but exposed for `bind:revealed`/`bind:total`.
|
|
1841
2318
|
|
|
1842
2319
|
#### Dispatched Events
|
|
1843
2320
|
|
|
1844
2321
|
- **on:done**: fires when typing finishes
|
|
2322
|
+
- **on:progress**: fires whenever `revealed` advances, with `{ revealed, total }`
|
|
1845
2323
|
|
|
1846
2324
|
```svelte
|
|
1847
2325
|
<Highlight language={typescript} {code} let:highlighted>
|
|
@@ -1855,7 +2333,7 @@ The highlighting engine's output is a flat scope-event stream (`ScopeEvent[]`):
|
|
|
1855
2333
|
|
|
1856
2334
|
### Stability tiers
|
|
1857
2335
|
|
|
1858
|
-
- **Stable, semver-governed:** `ScopeEvent`, `TEXT`/`OPEN`/`CLOSE`, `TokenRange`, `HighlightResult`, `LineToken`, `Renderer`, `renderHtml`, `toRanges`, `extendLines`, `tokenLines`, `escapeHtml`, `createHtmlRenderer`, `createRangeRenderer`, `createLineRenderer`, `Registry` and its methods, `createRegistry`, `registerAll`, `StreamSession`. `Snapshot` is a serializable format that round-trips within one library version, but is **not** guaranteed stable across versions — a snapshot from an older release may be rejected on resume.
|
|
2336
|
+
- **Stable, semver-governed:** `ScopeEvent`, `TEXT`/`OPEN`/`CLOSE`, `TokenRange`, `HighlightResult`, `LineToken`, `Renderer`, `renderHtml`, `toRanges`, `extendLines`, `tokenLines`, `escapeHtml`, `createHtmlRenderer`, `createRangeRenderer`, `createLineRenderer`, `Registry` and its methods, `createRegistry`, `registerAll`, `StreamSession`, `TokenizedDocument`, `createTokenizedDocument`. `Snapshot` is a serializable format that round-trips within one library version, but is **not** guaranteed stable across versions — a snapshot from an older release may be rejected on resume. The same caveat applies to `TokenizedDocument`: its method surface (`setCode`/`append`/`lineCount`/`lineRange`/`tokenizedThrough`/`checkpointCount`) is stable and semver-governed, but internally it resumes from `Snapshot`s the same way `StreamSession` does, so anything that tried to serialize and later resume a `TokenizedDocument`'s internal state directly would hit the same cross-version instability -- the public API doesn't expose that today.
|
|
1859
2337
|
- **Generated data, versioned with the library:** `GrammarIR`/`GrammarState`. These come from the build pipeline and are consumed by `registerAll`; treat them as opaque payloads whose field-level structure may change in any minor release. Always load grammars from the same package version as the engine.
|
|
1860
2338
|
|
|
1861
2339
|
### Headless highlighting, isolated registry
|
|
@@ -1896,6 +2374,7 @@ import { registry } from "svelte-highlight/registry";
|
|
|
1896
2374
|
|
|
1897
2375
|
const session = registry.createSession("typescript");
|
|
1898
2376
|
session.append(chunk); // repeat as chunks arrive
|
|
2377
|
+
session.replace(from, to, text); // patch an earlier range without restarting
|
|
1899
2378
|
const snapshot = session.snapshot(); // JSON-serializable checkpoint
|
|
1900
2379
|
const { value } = session.finish();
|
|
1901
2380
|
```
|