svelte-highlight 7.14.1 → 7.16.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 +22 -3
- package/CopyButton.svelte +10 -2
- package/CopyButton.svelte.d.ts +8 -1
- package/Highlight.svelte +15 -5
- package/Highlight.svelte.d.ts +15 -0
- package/HighlightAuto.svelte +29 -8
- package/HighlightAuto.svelte.d.ts +17 -0
- package/HighlightEditable.svelte +460 -45
- package/HighlightEditable.svelte.d.ts +35 -0
- package/HighlightStream.svelte +269 -0
- package/HighlightStream.svelte.d.ts +90 -0
- package/HighlightStyle.svelte +114 -12
- package/HighlightStyle.svelte.d.ts +25 -12
- package/HighlightSvelte.svelte +15 -5
- package/HighlightSvelte.svelte.d.ts +15 -0
- package/HighlightVirtual.svelte +229 -0
- package/HighlightVirtual.svelte.d.ts +36 -0
- package/LICENSE.highlight.txt +39 -0
- package/README.md +496 -35
- package/Typewriter.svelte +111 -58
- package/action.js +29 -6
- package/ansi.d.ts +9 -0
- package/ansi.js +112 -4
- package/compat.d.ts +13 -0
- package/compat.js +42 -0
- package/convert-language.d.ts +13 -0
- package/convert-language.js +203 -0
- package/copy-transforms.d.ts +13 -0
- package/copy-transforms.js +41 -0
- package/engine.d.ts +215 -0
- package/engine.js +1283 -0
- package/highlight-theme.d.ts +13 -0
- package/highlight-theme.js +253 -0
- package/incremental-tokenize.js +242 -0
- package/index.d.ts +4 -0
- package/index.js +3 -0
- package/languages/1c.js +1360 -3
- package/languages/abnf.js +89 -3
- package/languages/accesslog.js +88 -3
- package/languages/actionscript.js +221 -3
- package/languages/ada.js +235 -3
- package/languages/all.d.ts +4 -0
- package/languages/all.js +497 -0
- package/languages/angelscript.js +177 -3
- package/languages/apache.js +99 -3
- package/languages/applescript.js +291 -3
- package/languages/arcade.js +1040 -3
- package/languages/arduino.js +6201 -3
- package/languages/armasm.js +551 -3
- package/languages/asciidoc.js +237 -3
- package/languages/aspectj.js +770 -3
- package/languages/astro.js +70 -60
- package/languages/autohotkey.js +133 -3
- package/languages/autoit.js +598 -3
- package/languages/avrasm.js +372 -3
- package/languages/awk.js +115 -3
- package/languages/axapta.js +451 -3
- package/languages/bash.js +335 -3
- package/languages/basic.js +262 -3
- package/languages/bibtex.js +47 -45
- package/languages/bicep.js +141 -75
- package/languages/blade.js +96 -88
- package/languages/bnf.js +53 -3
- package/languages/brainfuck.js +69 -3
- package/languages/c.js +2283 -3
- package/languages/caddy.js +131 -56
- package/languages/cairo.js +165 -81
- package/languages/cal.js +197 -3
- package/languages/capnproto.js +105 -3
- package/languages/ceylon.js +188 -3
- package/languages/clarity.js +157 -52
- package/languages/clean.js +107 -3
- package/languages/clojure-repl.js +25 -3
- package/languages/clojure.js +553 -3
- package/languages/cmake.js +223 -3
- package/languages/coffeescript.js +827 -3
- package/languages/coq.js +447 -3
- package/languages/cos.js +183 -3
- package/languages/cpp.js +2288 -3
- package/languages/crmsh.js +201 -3
- package/languages/crystal.js +740 -3
- package/languages/csharp.js +1113 -3
- package/languages/csp.js +49 -3
- package/languages/css.js +216 -3
- package/languages/cue.js +137 -95
- package/languages/cypher.js +145 -67
- package/languages/d.js +244 -3
- package/languages/d2.js +118 -58
- package/languages/dart.js +309 -3
- package/languages/dax.js +270 -73
- package/languages/delphi.js +468 -3
- package/languages/dhall.js +160 -78
- package/languages/diff.js +37 -3
- package/languages/django.js +216 -3
- package/languages/dns.js +103 -3
- package/languages/dockerfile.js +82 -3
- package/languages/dos.js +173 -3
- package/languages/dotenv.js +71 -45
- package/languages/dsconfig.js +76 -3
- package/languages/dts.js +199 -3
- package/languages/dust.js +57 -3
- package/languages/ebnf.js +45 -3
- package/languages/elixir.js +517 -3
- package/languages/elm.js +172 -3
- package/languages/erb.js +39 -3
- package/languages/erlang-repl.js +108 -3
- package/languages/erlang.js +355 -3
- package/languages/excel.js +593 -3
- package/languages/fish.js +117 -73
- package/languages/fix.js +38 -3
- package/languages/flix.js +107 -3
- package/languages/fortran.js +630 -3
- package/languages/fsharp.js +850 -3
- package/languages/gams.js +705 -3
- package/languages/gauss.js +3845 -3
- package/languages/gcode.js +181 -3
- package/languages/gdscript.d.ts +2 -0
- package/languages/gdscript.js +158 -0
- package/languages/gherkin.js +68 -3
- package/languages/gleam.js +115 -68
- package/languages/glsl.js +638 -3
- package/languages/gml.js +3151 -3
- package/languages/go.js +253 -3
- package/languages/golo.js +97 -3
- package/languages/gradle.js +233 -3
- package/languages/graphql.js +101 -3
- package/languages/groovy.js +209 -3
- package/languages/groq.js +94 -86
- package/languages/haml.js +111 -3
- package/languages/handlebars.js +368 -3
- package/languages/haskell.js +272 -3
- package/languages/haxe.js +290 -3
- package/languages/hcl.js +143 -80
- package/languages/heex.d.ts +2 -0
- package/languages/heex.js +130 -0
- package/languages/hlsl.js +303 -89
- package/languages/hsp.js +490 -3
- package/languages/html.js +203 -158
- package/languages/http.js +84 -3
- package/languages/hy.js +423 -3
- package/languages/index.d.ts +11 -2
- package/languages/index.js +3 -0
- package/languages/inform7.js +63 -3
- package/languages/ini.js +89 -3
- package/languages/irpf90.js +612 -3
- package/languages/isbl.js +10135 -3
- package/languages/java.js +550 -3
- package/languages/javascript.js +1240 -3
- package/languages/jboss-cli.js +114 -3
- package/languages/jq.js +328 -117
- package/languages/json.js +96 -3
- package/languages/json5.js +107 -53
- package/languages/jsonc.js +75 -34
- package/languages/jsonnet.js +138 -68
- package/languages/julia-repl.js +33 -3
- package/languages/julia.js +621 -3
- package/languages/just.js +225 -116
- package/languages/kotlin.js +595 -3
- package/languages/kql.js +275 -113
- package/languages/lasso.js +568 -3
- package/languages/latex.js +670 -3
- package/languages/ldif.js +41 -3
- package/languages/leaf.js +60 -3
- package/languages/less.js +787 -3
- package/languages/liquid.js +113 -54
- package/languages/lisp.js +150 -3
- package/languages/livecodeserver.js +828 -3
- package/languages/livescript.js +1082 -3
- package/languages/llvm.js +369 -3
- package/languages/logql.js +119 -79
- package/languages/lsl.js +130 -3
- package/languages/lua.js +278 -3
- package/languages/makefile.js +124 -3
- package/languages/markdown.js +222 -3
- package/languages/marko.js +148 -165
- package/languages/mathematica.js +99 -3
- package/languages/matlab.js +335 -3
- package/languages/maxima.js +2495 -3
- package/languages/mdx.js +106 -74
- package/languages/mel.js +1309 -3
- package/languages/mercury.js +231 -3
- package/languages/mipsasm.js +289 -3
- package/languages/mizar.js +115 -3
- package/languages/mojolicious.js +32 -3
- package/languages/monkey.js +205 -3
- package/languages/moonscript.js +334 -3
- package/languages/move.js +149 -89
- package/languages/n1ql.js +375 -3
- package/languages/nestedtext.js +76 -3
- package/languages/nginx.js +201 -3
- package/languages/nickel.js +126 -77
- package/languages/nim.js +206 -3
- package/languages/nix.js +310 -3
- package/languages/node-repl.js +33 -3
- package/languages/nsis.js +441 -3
- package/languages/nushell.js +158 -97
- package/languages/objectivec.js +303 -3
- package/languages/ocaml.js +165 -3
- package/languages/odin.js +176 -75
- package/languages/openscad.js +185 -3
- package/languages/oxygene.js +459 -3
- package/languages/parser3.js +111 -3
- package/languages/perl.js +864 -3
- package/languages/pf.js +168 -3
- package/languages/pgsql.js +1253 -3
- package/languages/php-template.js +28 -3
- package/languages/php.js +1031 -3
- package/languages/pkl.js +190 -76
- package/languages/plaintext.js +17 -3
- package/languages/pony.js +132 -3
- package/languages/powershell.js +405 -3
- package/languages/prisma.js +95 -68
- package/languages/processing.js +445 -3
- package/languages/profile.js +66 -3
- package/languages/prolog.js +142 -3
- package/languages/promql.js +204 -91
- package/languages/properties.js +75 -3
- package/languages/protobuf.js +106 -3
- package/languages/pug.js +119 -67
- package/languages/puppet.js +415 -3
- package/languages/purebasic.js +187 -3
- package/languages/python-repl.js +35 -3
- package/languages/python.js +784 -3
- package/languages/q.js +215 -3
- package/languages/qml.js +401 -3
- package/languages/r.js +351 -3
- package/languages/razor.js +417 -126
- package/languages/reasonml.js +207 -3
- package/languages/rego.js +179 -91
- package/languages/rescript.js +202 -138
- package/languages/rib.js +148 -3
- package/languages/roboconf.js +128 -3
- package/languages/routeros.js +169 -3
- package/languages/rsl.js +175 -3
- package/languages/rst.js +111 -142
- package/languages/ruby.js +890 -3
- package/languages/ruleslanguage.js +377 -3
- package/languages/rust.js +392 -3
- package/languages/sas.js +211 -3
- package/languages/scala.js +332 -3
- package/languages/scheme.js +398 -3
- package/languages/scilab.js +190 -3
- package/languages/scss.js +236 -3
- package/languages/shell.js +32 -3
- package/languages/smali.js +91 -3
- package/languages/smalltalk.js +89 -3
- package/languages/sml.js +145 -3
- package/languages/solidity.js +400 -99
- package/languages/sparql.d.ts +2 -0
- package/languages/sparql.js +153 -0
- package/languages/sqf.js +2641 -3
- package/languages/sql.js +474 -3
- package/languages/stan.js +526 -3
- package/languages/starlark.js +122 -51
- package/languages/stata.js +1903 -3
- package/languages/step21.js +100 -3
- package/languages/stylus.js +261 -3
- package/languages/subunit.js +59 -3
- package/languages/svelte.js +148 -141
- package/languages/swift.js +2245 -3
- package/languages/taggerscript.js +51 -3
- package/languages/tap.js +48 -3
- package/languages/tcl.js +218 -3
- package/languages/templ.js +254 -250
- package/languages/thrift.js +129 -3
- package/languages/toml.js +107 -74
- package/languages/tp.js +209 -3
- package/languages/twig.js +204 -3
- package/languages/typescript.js +1410 -3
- package/languages/typst.js +340 -183
- package/languages/v.js +230 -101
- package/languages/vala.js +161 -3
- package/languages/vbnet.js +333 -3
- package/languages/vbscript-html.js +18 -3
- package/languages/vbscript.js +225 -3
- package/languages/verilog.js +576 -3
- package/languages/vhdl.js +229 -3
- package/languages/vim.js +1294 -3
- package/languages/vue.js +99 -98
- package/languages/vyper.js +144 -72
- package/languages/wasm.js +140 -3
- package/languages/wgsl.js +370 -67
- package/languages/wren.js +311 -3
- package/languages/x86asm.js +2330 -3
- package/languages/xl.js +474 -3
- package/languages/xml.js +198 -3
- package/languages/xquery.js +315 -3
- package/languages/yaml.js +267 -3
- package/languages/zephir.js +333 -3
- package/languages/zig.js +196 -100
- package/package.json +61 -2
- package/preprocessor.js +3 -5
- package/registry.d.ts +17 -0
- package/registry.js +17 -0
- package/text-diff.d.ts +8 -0
- package/text-diff.js +46 -0
- package/textmate-theme.d.ts +41 -0
- package/textmate-theme.js +211 -0
- package/theme-style.js +94 -0
- package/theme-vars.js +205 -0
- package/theme.d.ts +104 -0
- package/theme.js +130 -0
- package/themes/1c-light.css +1 -0
- package/themes/1c-light.d.ts +1 -0
- package/themes/1c-light.js +53 -0
- package/themes/3024.css +1 -0
- package/themes/3024.d.ts +1 -0
- package/themes/3024.js +62 -0
- package/themes/_shl-fallbacks.d.ts +1 -0
- package/themes/_shl-fallbacks.js +27 -0
- package/themes/a11y-dark.css +29 -0
- package/themes/a11y-dark.d.ts +1 -0
- package/themes/a11y-dark.js +47 -0
- package/themes/a11y-light.css +29 -0
- package/themes/a11y-light.d.ts +1 -0
- package/themes/a11y-light.js +47 -0
- package/themes/agate.css +1 -0
- package/themes/agate.d.ts +1 -0
- package/themes/agate.js +58 -0
- package/themes/an-old-hope.css +1 -0
- package/themes/an-old-hope.d.ts +1 -0
- package/themes/an-old-hope.js +45 -0
- package/themes/androidstudio.css +1 -0
- package/themes/androidstudio.d.ts +1 -0
- package/themes/androidstudio.js +45 -0
- package/themes/apathy.css +1 -0
- package/themes/apathy.d.ts +1 -0
- package/themes/apathy.js +62 -0
- package/themes/apprentice.css +1 -0
- package/themes/apprentice.d.ts +1 -0
- package/themes/apprentice.js +62 -0
- package/themes/arduino-light.css +1 -0
- package/themes/arduino-light.d.ts +1 -0
- package/themes/arduino-light.js +52 -0
- package/themes/arta.css +1 -0
- package/themes/arta.d.ts +1 -0
- package/themes/arta.js +50 -0
- package/themes/ascetic.css +1 -0
- package/themes/ascetic.d.ts +1 -0
- package/themes/ascetic.js +45 -0
- package/themes/ashes.css +1 -0
- package/themes/ashes.d.ts +1 -0
- package/themes/ashes.js +62 -0
- package/themes/atelier-cave-light.css +1 -0
- package/themes/atelier-cave-light.d.ts +1 -0
- package/themes/atelier-cave-light.js +62 -0
- package/themes/atelier-cave.css +1 -0
- package/themes/atelier-cave.d.ts +1 -0
- package/themes/atelier-cave.js +62 -0
- package/themes/atelier-dune-light.css +1 -0
- package/themes/atelier-dune-light.d.ts +1 -0
- package/themes/atelier-dune-light.js +62 -0
- package/themes/atelier-dune.css +1 -0
- package/themes/atelier-dune.d.ts +1 -0
- package/themes/atelier-dune.js +62 -0
- package/themes/atelier-estuary-light.css +1 -0
- package/themes/atelier-estuary-light.d.ts +1 -0
- package/themes/atelier-estuary-light.js +62 -0
- package/themes/atelier-estuary.css +1 -0
- package/themes/atelier-estuary.d.ts +1 -0
- package/themes/atelier-estuary.js +62 -0
- package/themes/atelier-forest-light.css +1 -0
- package/themes/atelier-forest-light.d.ts +1 -0
- package/themes/atelier-forest-light.js +62 -0
- package/themes/atelier-forest.css +1 -0
- package/themes/atelier-forest.d.ts +1 -0
- package/themes/atelier-forest.js +62 -0
- package/themes/atelier-heath-light.css +1 -0
- package/themes/atelier-heath-light.d.ts +1 -0
- package/themes/atelier-heath-light.js +62 -0
- package/themes/atelier-heath.css +1 -0
- package/themes/atelier-heath.d.ts +1 -0
- package/themes/atelier-heath.js +62 -0
- package/themes/atelier-lakeside-light.css +1 -0
- package/themes/atelier-lakeside-light.d.ts +1 -0
- package/themes/atelier-lakeside-light.js +62 -0
- package/themes/atelier-lakeside.css +1 -0
- package/themes/atelier-lakeside.d.ts +1 -0
- package/themes/atelier-lakeside.js +62 -0
- package/themes/atelier-plateau-light.css +1 -0
- package/themes/atelier-plateau-light.d.ts +1 -0
- package/themes/atelier-plateau-light.js +62 -0
- package/themes/atelier-plateau.css +1 -0
- package/themes/atelier-plateau.d.ts +1 -0
- package/themes/atelier-plateau.js +62 -0
- package/themes/atelier-savanna-light.css +1 -0
- package/themes/atelier-savanna-light.d.ts +1 -0
- package/themes/atelier-savanna-light.js +62 -0
- package/themes/atelier-savanna.css +1 -0
- package/themes/atelier-savanna.d.ts +1 -0
- package/themes/atelier-savanna.js +62 -0
- package/themes/atelier-seaside-light.css +1 -0
- package/themes/atelier-seaside-light.d.ts +1 -0
- package/themes/atelier-seaside-light.js +62 -0
- package/themes/atelier-seaside.css +1 -0
- package/themes/atelier-seaside.d.ts +1 -0
- package/themes/atelier-seaside.js +62 -0
- package/themes/atelier-sulphurpool-light.css +1 -0
- package/themes/atelier-sulphurpool-light.d.ts +1 -0
- package/themes/atelier-sulphurpool-light.js +62 -0
- package/themes/atelier-sulphurpool.css +1 -0
- package/themes/atelier-sulphurpool.d.ts +1 -0
- package/themes/atelier-sulphurpool.js +62 -0
- package/themes/atlas.css +1 -0
- package/themes/atlas.d.ts +1 -0
- package/themes/atlas.js +62 -0
- package/themes/atom-one-dark-reasonable.css +1 -0
- package/themes/atom-one-dark-reasonable.d.ts +1 -0
- package/themes/atom-one-dark-reasonable.js +62 -0
- package/themes/atom-one-dark.css +1 -0
- package/themes/atom-one-dark.d.ts +1 -0
- package/themes/atom-one-dark.js +54 -0
- package/themes/atom-one-light.css +1 -0
- package/themes/atom-one-light.d.ts +1 -0
- package/themes/atom-one-light.js +54 -0
- package/themes/base.css +1 -0
- package/themes/base16-github.css +1 -0
- package/themes/base16-github.d.ts +1 -0
- package/themes/base16-github.js +62 -0
- package/themes/base16-ir-black.css +1 -0
- package/themes/base16-ir-black.d.ts +1 -0
- package/themes/base16-ir-black.js +62 -0
- package/themes/base16-monokai.css +1 -0
- package/themes/base16-monokai.d.ts +1 -0
- package/themes/base16-monokai.js +62 -0
- package/themes/base16-nord.css +1 -0
- package/themes/base16-nord.d.ts +1 -0
- package/themes/base16-nord.js +62 -0
- package/themes/bespin.css +1 -0
- package/themes/bespin.d.ts +1 -0
- package/themes/bespin.js +62 -0
- package/themes/black-metal-bathory.css +1 -0
- package/themes/black-metal-bathory.d.ts +1 -0
- package/themes/black-metal-bathory.js +62 -0
- package/themes/black-metal-burzum.css +1 -0
- package/themes/black-metal-burzum.d.ts +1 -0
- package/themes/black-metal-burzum.js +62 -0
- package/themes/black-metal-dark-funeral.css +1 -0
- package/themes/black-metal-dark-funeral.d.ts +1 -0
- package/themes/black-metal-dark-funeral.js +62 -0
- package/themes/black-metal-gorgoroth.css +1 -0
- package/themes/black-metal-gorgoroth.d.ts +1 -0
- package/themes/black-metal-gorgoroth.js +62 -0
- package/themes/black-metal-immortal.css +1 -0
- package/themes/black-metal-immortal.d.ts +1 -0
- package/themes/black-metal-immortal.js +62 -0
- package/themes/black-metal-khold.css +1 -0
- package/themes/black-metal-khold.d.ts +1 -0
- package/themes/black-metal-khold.js +62 -0
- package/themes/black-metal-marduk.css +1 -0
- package/themes/black-metal-marduk.d.ts +1 -0
- package/themes/black-metal-marduk.js +62 -0
- package/themes/black-metal-mayhem.css +1 -0
- package/themes/black-metal-mayhem.d.ts +1 -0
- package/themes/black-metal-mayhem.js +62 -0
- package/themes/black-metal-nile.css +1 -0
- package/themes/black-metal-nile.d.ts +1 -0
- package/themes/black-metal-nile.js +62 -0
- package/themes/black-metal-venom.css +1 -0
- package/themes/black-metal-venom.d.ts +1 -0
- package/themes/black-metal-venom.js +62 -0
- package/themes/black-metal.css +1 -0
- package/themes/black-metal.d.ts +1 -0
- package/themes/black-metal.js +62 -0
- package/themes/brewer.css +1 -0
- package/themes/brewer.d.ts +1 -0
- package/themes/brewer.js +62 -0
- package/themes/bright.css +1 -0
- package/themes/bright.d.ts +1 -0
- package/themes/bright.js +62 -0
- package/themes/brogrammer.css +1 -0
- package/themes/brogrammer.d.ts +1 -0
- package/themes/brogrammer.js +62 -0
- package/themes/brown-paper.css +1 -0
- package/themes/brown-paper.d.ts +1 -0
- package/themes/brown-paper.js +53 -0
- package/themes/brush-trees-dark.css +1 -0
- package/themes/brush-trees-dark.d.ts +1 -0
- package/themes/brush-trees-dark.js +62 -0
- package/themes/brush-trees.css +1 -0
- package/themes/brush-trees.d.ts +1 -0
- package/themes/brush-trees.js +62 -0
- package/themes/chalk.css +1 -0
- package/themes/chalk.d.ts +1 -0
- package/themes/chalk.js +62 -0
- package/themes/circus.css +1 -0
- package/themes/circus.d.ts +1 -0
- package/themes/circus.js +62 -0
- package/themes/classic-dark.css +1 -0
- package/themes/classic-dark.d.ts +1 -0
- package/themes/classic-dark.js +62 -0
- package/themes/classic-light.css +1 -0
- package/themes/classic-light.d.ts +1 -0
- package/themes/classic-light.js +62 -0
- package/themes/codepen-embed.css +1 -0
- package/themes/codepen-embed.d.ts +1 -0
- package/themes/codepen-embed.js +45 -0
- package/themes/codeschool.css +1 -0
- package/themes/codeschool.d.ts +1 -0
- package/themes/codeschool.js +62 -0
- package/themes/color-brewer.css +1 -0
- package/themes/color-brewer.d.ts +1 -0
- package/themes/color-brewer.js +45 -0
- package/themes/colors.css +1 -0
- package/themes/colors.d.ts +1 -0
- package/themes/colors.js +62 -0
- package/themes/cupcake.css +1 -0
- package/themes/cupcake.d.ts +1 -0
- package/themes/cupcake.js +62 -0
- package/themes/cupertino.css +1 -0
- package/themes/cupertino.d.ts +1 -0
- package/themes/cupertino.js +62 -0
- package/themes/cybertopia-cherry.css +1 -0
- package/themes/cybertopia-cherry.d.ts +1 -0
- package/themes/cybertopia-cherry.js +61 -0
- package/themes/cybertopia-dimmer.css +1 -0
- package/themes/cybertopia-dimmer.d.ts +1 -0
- package/themes/cybertopia-dimmer.js +61 -0
- package/themes/cybertopia-icecap.css +1 -0
- package/themes/cybertopia-icecap.d.ts +1 -0
- package/themes/cybertopia-icecap.js +61 -0
- package/themes/cybertopia-saturated.css +1 -0
- package/themes/cybertopia-saturated.d.ts +1 -0
- package/themes/cybertopia-saturated.js +61 -0
- package/themes/danqing.css +1 -0
- package/themes/danqing.d.ts +1 -0
- package/themes/danqing.js +62 -0
- package/themes/darcula.css +1 -0
- package/themes/darcula.d.ts +1 -0
- package/themes/darcula.js +62 -0
- package/themes/dark-violet.css +1 -0
- package/themes/dark-violet.d.ts +1 -0
- package/themes/dark-violet.js +62 -0
- package/themes/dark.css +1 -0
- package/themes/dark.d.ts +1 -0
- package/themes/dark.js +52 -0
- package/themes/darkmoss.css +1 -0
- package/themes/darkmoss.d.ts +1 -0
- package/themes/darkmoss.js +62 -0
- package/themes/darktooth.css +1 -0
- package/themes/darktooth.d.ts +1 -0
- package/themes/darktooth.js +62 -0
- package/themes/decaf.css +1 -0
- package/themes/decaf.d.ts +1 -0
- package/themes/decaf.js +62 -0
- package/themes/default-dark.css +1 -0
- package/themes/default-dark.d.ts +1 -0
- package/themes/default-dark.js +62 -0
- package/themes/default-light.css +1 -0
- package/themes/default-light.d.ts +1 -0
- package/themes/default-light.js +62 -0
- package/themes/default.css +1 -0
- package/themes/default.d.ts +1 -0
- package/themes/default.js +59 -0
- package/themes/devibeans.css +1 -0
- package/themes/devibeans.d.ts +1 -0
- package/themes/devibeans.js +52 -0
- package/themes/dirtysea.css +1 -0
- package/themes/dirtysea.d.ts +1 -0
- package/themes/dirtysea.js +62 -0
- package/themes/docco.css +1 -0
- package/themes/docco.d.ts +1 -0
- package/themes/docco.js +57 -0
- package/themes/dracula.css +1 -0
- package/themes/dracula.d.ts +1 -0
- package/themes/dracula.js +62 -0
- package/themes/edge-dark.css +1 -0
- package/themes/edge-dark.d.ts +1 -0
- package/themes/edge-dark.js +62 -0
- package/themes/edge-light.css +1 -0
- package/themes/edge-light.d.ts +1 -0
- package/themes/edge-light.js +62 -0
- package/themes/eighties.css +1 -0
- package/themes/eighties.d.ts +1 -0
- package/themes/eighties.js +62 -0
- package/themes/embers.css +1 -0
- package/themes/embers.d.ts +1 -0
- package/themes/embers.js +62 -0
- package/themes/equilibrium-dark.css +1 -0
- package/themes/equilibrium-dark.d.ts +1 -0
- package/themes/equilibrium-dark.js +62 -0
- package/themes/equilibrium-gray-dark.css +1 -0
- package/themes/equilibrium-gray-dark.d.ts +1 -0
- package/themes/equilibrium-gray-dark.js +62 -0
- package/themes/equilibrium-gray-light.css +1 -0
- package/themes/equilibrium-gray-light.d.ts +1 -0
- package/themes/equilibrium-gray-light.js +62 -0
- package/themes/equilibrium-light.css +1 -0
- package/themes/equilibrium-light.d.ts +1 -0
- package/themes/equilibrium-light.js +62 -0
- package/themes/espresso.css +1 -0
- package/themes/espresso.d.ts +1 -0
- package/themes/espresso.js +62 -0
- package/themes/eva-dim.css +1 -0
- package/themes/eva-dim.d.ts +1 -0
- package/themes/eva-dim.js +62 -0
- package/themes/eva.css +1 -0
- package/themes/eva.d.ts +1 -0
- package/themes/eva.js +62 -0
- package/themes/far.css +1 -0
- package/themes/far.d.ts +1 -0
- package/themes/far.js +50 -0
- package/themes/felipec.css +1 -0
- package/themes/felipec.d.ts +1 -0
- package/themes/felipec.js +54 -0
- package/themes/flat.css +1 -0
- package/themes/flat.d.ts +1 -0
- package/themes/flat.js +62 -0
- package/themes/foundation.css +1 -0
- package/themes/foundation.d.ts +1 -0
- package/themes/foundation.js +52 -0
- package/themes/framer.css +1 -0
- package/themes/framer.d.ts +1 -0
- package/themes/framer.js +62 -0
- package/themes/fruit-soda.css +1 -0
- package/themes/fruit-soda.d.ts +1 -0
- package/themes/fruit-soda.js +62 -0
- package/themes/gigavolt.css +1 -0
- package/themes/gigavolt.d.ts +1 -0
- package/themes/gigavolt.js +62 -0
- package/themes/github-dark-dimmed.css +1 -0
- package/themes/github-dark-dimmed.d.ts +1 -0
- package/themes/github-dark-dimmed.js +59 -0
- package/themes/github-dark.css +1 -0
- package/themes/github-dark.d.ts +1 -0
- package/themes/github-dark.js +59 -0
- package/themes/github.css +1 -0
- package/themes/github.d.ts +1 -0
- package/themes/github.js +59 -0
- package/themes/gml.css +1 -0
- package/themes/gml.d.ts +1 -0
- package/themes/gml.js +51 -0
- package/themes/google-dark.css +1 -0
- package/themes/google-dark.d.ts +1 -0
- package/themes/google-dark.js +62 -0
- package/themes/google-light.css +1 -0
- package/themes/google-light.d.ts +1 -0
- package/themes/google-light.js +62 -0
- package/themes/googlecode.css +1 -0
- package/themes/googlecode.d.ts +1 -0
- package/themes/googlecode.js +53 -0
- package/themes/gradient-dark.css +1 -0
- package/themes/gradient-dark.d.ts +1 -0
- package/themes/gradient-dark.js +60 -0
- package/themes/gradient-light.css +1 -0
- package/themes/gradient-light.d.ts +1 -0
- package/themes/gradient-light.js +60 -0
- package/themes/grayscale-dark.css +1 -0
- package/themes/grayscale-dark.d.ts +1 -0
- package/themes/grayscale-dark.js +62 -0
- package/themes/grayscale-light.css +1 -0
- package/themes/grayscale-light.d.ts +1 -0
- package/themes/grayscale-light.js +62 -0
- package/themes/grayscale.css +1 -0
- package/themes/grayscale.d.ts +1 -0
- package/themes/grayscale.js +66 -0
- package/themes/green-screen.css +1 -0
- package/themes/green-screen.d.ts +1 -0
- package/themes/green-screen.js +62 -0
- package/themes/gruvbox-dark-hard.css +1 -0
- package/themes/gruvbox-dark-hard.d.ts +1 -0
- package/themes/gruvbox-dark-hard.js +62 -0
- package/themes/gruvbox-dark-medium.css +1 -0
- package/themes/gruvbox-dark-medium.d.ts +1 -0
- package/themes/gruvbox-dark-medium.js +62 -0
- package/themes/gruvbox-dark-pale.css +1 -0
- package/themes/gruvbox-dark-pale.d.ts +1 -0
- package/themes/gruvbox-dark-pale.js +62 -0
- package/themes/gruvbox-dark-soft.css +1 -0
- package/themes/gruvbox-dark-soft.d.ts +1 -0
- package/themes/gruvbox-dark-soft.js +62 -0
- package/themes/gruvbox-light-hard.css +1 -0
- package/themes/gruvbox-light-hard.d.ts +1 -0
- package/themes/gruvbox-light-hard.js +62 -0
- package/themes/gruvbox-light-medium.css +1 -0
- package/themes/gruvbox-light-medium.d.ts +1 -0
- package/themes/gruvbox-light-medium.js +62 -0
- package/themes/gruvbox-light-soft.css +1 -0
- package/themes/gruvbox-light-soft.d.ts +1 -0
- package/themes/gruvbox-light-soft.js +62 -0
- package/themes/hardcore.css +1 -0
- package/themes/hardcore.d.ts +1 -0
- package/themes/hardcore.js +62 -0
- package/themes/harmonic16-dark.css +1 -0
- package/themes/harmonic16-dark.d.ts +1 -0
- package/themes/harmonic16-dark.js +62 -0
- package/themes/harmonic16-light.css +1 -0
- package/themes/harmonic16-light.d.ts +1 -0
- package/themes/harmonic16-light.js +62 -0
- package/themes/heetch-dark.css +1 -0
- package/themes/heetch-dark.d.ts +1 -0
- package/themes/heetch-dark.js +62 -0
- package/themes/heetch-light.css +1 -0
- package/themes/heetch-light.d.ts +1 -0
- package/themes/heetch-light.js +62 -0
- package/themes/helios.css +1 -0
- package/themes/helios.d.ts +1 -0
- package/themes/helios.js +62 -0
- package/themes/hopscotch.css +1 -0
- package/themes/hopscotch.d.ts +1 -0
- package/themes/hopscotch.js +62 -0
- package/themes/horizon-dark.css +1 -0
- package/themes/horizon-dark.d.ts +1 -0
- package/themes/horizon-dark.js +62 -0
- package/themes/horizon-light.css +1 -0
- package/themes/horizon-light.d.ts +1 -0
- package/themes/horizon-light.js +62 -0
- package/themes/humanoid-dark.css +1 -0
- package/themes/humanoid-dark.d.ts +1 -0
- package/themes/humanoid-dark.js +62 -0
- package/themes/humanoid-light.css +1 -0
- package/themes/humanoid-light.d.ts +1 -0
- package/themes/humanoid-light.js +62 -0
- package/themes/hybrid.css +1 -0
- package/themes/hybrid.d.ts +1 -0
- package/themes/hybrid.js +51 -0
- package/themes/ia-dark.css +1 -0
- package/themes/ia-dark.d.ts +1 -0
- package/themes/ia-dark.js +62 -0
- package/themes/ia-light.css +1 -0
- package/themes/ia-light.d.ts +1 -0
- package/themes/ia-light.js +62 -0
- package/themes/icy-dark.css +1 -0
- package/themes/icy-dark.d.ts +1 -0
- package/themes/icy-dark.js +62 -0
- package/themes/idea.css +1 -0
- package/themes/idea.d.ts +1 -0
- package/themes/idea.js +75 -0
- package/themes/index.d.ts +258 -0
- package/themes/index.js +256 -0
- package/themes/intellij-light.css +1 -0
- package/themes/intellij-light.d.ts +1 -0
- package/themes/intellij-light.js +63 -0
- package/themes/ir-black.css +1 -0
- package/themes/ir-black.d.ts +1 -0
- package/themes/ir-black.js +48 -0
- package/themes/isbl-editor-dark.css +1 -0
- package/themes/isbl-editor-dark.d.ts +1 -0
- package/themes/isbl-editor-dark.js +62 -0
- package/themes/isbl-editor-light.css +1 -0
- package/themes/isbl-editor-light.d.ts +1 -0
- package/themes/isbl-editor-light.js +62 -0
- package/themes/isotope.css +1 -0
- package/themes/isotope.d.ts +1 -0
- package/themes/isotope.js +62 -0
- package/themes/kimber.css +1 -0
- package/themes/kimber.d.ts +1 -0
- package/themes/kimber.js +62 -0
- package/themes/kimbie-dark.css +1 -0
- package/themes/kimbie-dark.d.ts +1 -0
- package/themes/kimbie-dark.js +47 -0
- package/themes/kimbie-light.css +1 -0
- package/themes/kimbie-light.d.ts +1 -0
- package/themes/kimbie-light.js +47 -0
- package/themes/lightfair.css +1 -0
- package/themes/lightfair.d.ts +1 -0
- package/themes/lightfair.js +54 -0
- package/themes/lioshi.css +1 -0
- package/themes/lioshi.d.ts +1 -0
- package/themes/lioshi.js +49 -0
- package/themes/london-tube.css +1 -0
- package/themes/london-tube.d.ts +1 -0
- package/themes/london-tube.js +62 -0
- package/themes/macintosh.css +1 -0
- package/themes/macintosh.d.ts +1 -0
- package/themes/macintosh.js +62 -0
- package/themes/magula.css +1 -0
- package/themes/magula.d.ts +1 -0
- package/themes/magula.js +56 -0
- package/themes/marrakesh.css +1 -0
- package/themes/marrakesh.d.ts +1 -0
- package/themes/marrakesh.js +62 -0
- package/themes/materia.css +1 -0
- package/themes/materia.d.ts +1 -0
- package/themes/materia.js +62 -0
- package/themes/material-darker.css +1 -0
- package/themes/material-darker.d.ts +1 -0
- package/themes/material-darker.js +62 -0
- package/themes/material-lighter.css +1 -0
- package/themes/material-lighter.d.ts +1 -0
- package/themes/material-lighter.js +62 -0
- package/themes/material-palenight.css +1 -0
- package/themes/material-palenight.d.ts +1 -0
- package/themes/material-palenight.js +62 -0
- package/themes/material-vivid.css +1 -0
- package/themes/material-vivid.d.ts +1 -0
- package/themes/material-vivid.js +62 -0
- package/themes/material.css +1 -0
- package/themes/material.d.ts +1 -0
- package/themes/material.js +62 -0
- package/themes/mellow-purple.css +1 -0
- package/themes/mellow-purple.d.ts +1 -0
- package/themes/mellow-purple.js +62 -0
- package/themes/mexico-light.css +1 -0
- package/themes/mexico-light.d.ts +1 -0
- package/themes/mexico-light.js +62 -0
- package/themes/mocha.css +1 -0
- package/themes/mocha.d.ts +1 -0
- package/themes/mocha.js +62 -0
- package/themes/mono-blue.css +1 -0
- package/themes/mono-blue.d.ts +1 -0
- package/themes/mono-blue.js +54 -0
- package/themes/monokai-sublime.css +1 -0
- package/themes/monokai-sublime.d.ts +1 -0
- package/themes/monokai-sublime.js +52 -0
- package/themes/monokai.css +1 -0
- package/themes/monokai.d.ts +1 -0
- package/themes/monokai.js +58 -0
- package/themes/nebula.css +1 -0
- package/themes/nebula.d.ts +1 -0
- package/themes/nebula.js +62 -0
- package/themes/night-owl.css +1 -0
- package/themes/night-owl.d.ts +1 -0
- package/themes/night-owl.js +64 -0
- package/themes/nnfx-dark.css +1 -0
- package/themes/nnfx-dark.d.ts +1 -0
- package/themes/nnfx-dark.js +74 -0
- package/themes/nnfx-light.css +1 -0
- package/themes/nnfx-light.d.ts +1 -0
- package/themes/nnfx-light.js +74 -0
- package/themes/nord.css +1 -0
- package/themes/nord.d.ts +1 -0
- package/themes/nord.js +59 -0
- package/themes/nova.css +1 -0
- package/themes/nova.d.ts +1 -0
- package/themes/nova.js +62 -0
- package/themes/obsidian.css +1 -0
- package/themes/obsidian.d.ts +1 -0
- package/themes/obsidian.js +58 -0
- package/themes/ocean.css +1 -0
- package/themes/ocean.d.ts +1 -0
- package/themes/ocean.js +62 -0
- package/themes/oceanicnext.css +1 -0
- package/themes/oceanicnext.d.ts +1 -0
- package/themes/oceanicnext.js +62 -0
- package/themes/one-light.css +1 -0
- package/themes/one-light.d.ts +1 -0
- package/themes/one-light.js +62 -0
- package/themes/onedark.css +1 -0
- package/themes/onedark.d.ts +1 -0
- package/themes/onedark.js +62 -0
- package/themes/outrun-dark.css +1 -0
- package/themes/outrun-dark.d.ts +1 -0
- package/themes/outrun-dark.js +62 -0
- package/themes/panda-syntax-dark.css +1 -0
- package/themes/panda-syntax-dark.d.ts +1 -0
- package/themes/panda-syntax-dark.js +59 -0
- package/themes/panda-syntax-light.css +1 -0
- package/themes/panda-syntax-light.d.ts +1 -0
- package/themes/panda-syntax-light.js +59 -0
- package/themes/papercolor-dark.css +1 -0
- package/themes/papercolor-dark.d.ts +1 -0
- package/themes/papercolor-dark.js +62 -0
- package/themes/papercolor-light.css +1 -0
- package/themes/papercolor-light.d.ts +1 -0
- package/themes/papercolor-light.js +62 -0
- package/themes/paraiso-dark.css +1 -0
- package/themes/paraiso-dark.d.ts +1 -0
- package/themes/paraiso-dark.js +45 -0
- package/themes/paraiso-light.css +1 -0
- package/themes/paraiso-light.d.ts +1 -0
- package/themes/paraiso-light.js +45 -0
- package/themes/paraiso.css +1 -0
- package/themes/paraiso.d.ts +1 -0
- package/themes/paraiso.js +62 -0
- package/themes/pasque.css +1 -0
- package/themes/pasque.d.ts +1 -0
- package/themes/pasque.js +62 -0
- package/themes/phd.css +1 -0
- package/themes/phd.d.ts +1 -0
- package/themes/phd.js +62 -0
- package/themes/pico.css +1 -0
- package/themes/pico.d.ts +1 -0
- package/themes/pico.js +62 -0
- package/themes/pojoaque.css +1 -0
- package/themes/pojoaque.d.ts +1 -0
- package/themes/pojoaque.js +54 -0
- package/themes/pop.css +1 -0
- package/themes/pop.d.ts +1 -0
- package/themes/pop.js +62 -0
- package/themes/porple.css +1 -0
- package/themes/porple.d.ts +1 -0
- package/themes/porple.js +62 -0
- package/themes/purebasic.css +1 -0
- package/themes/purebasic.d.ts +1 -0
- package/themes/purebasic.js +60 -0
- package/themes/qtcreator-dark.css +1 -0
- package/themes/qtcreator-dark.d.ts +1 -0
- package/themes/qtcreator-dark.js +55 -0
- package/themes/qtcreator-light.css +1 -0
- package/themes/qtcreator-light.d.ts +1 -0
- package/themes/qtcreator-light.js +55 -0
- package/themes/qualia.css +1 -0
- package/themes/qualia.d.ts +1 -0
- package/themes/qualia.js +62 -0
- package/themes/railscasts.css +1 -0
- package/themes/railscasts.d.ts +1 -0
- package/themes/railscasts.js +62 -0
- package/themes/rainbow.css +1 -0
- package/themes/rainbow.d.ts +1 -0
- package/themes/rainbow.js +55 -0
- package/themes/rebecca.css +1 -0
- package/themes/rebecca.d.ts +1 -0
- package/themes/rebecca.js +62 -0
- package/themes/ros-pine-dawn.css +1 -0
- package/themes/ros-pine-dawn.d.ts +1 -0
- package/themes/ros-pine-dawn.js +62 -0
- package/themes/ros-pine-moon.css +1 -0
- package/themes/ros-pine-moon.d.ts +1 -0
- package/themes/ros-pine-moon.js +62 -0
- package/themes/ros-pine.css +1 -0
- package/themes/ros-pine.d.ts +1 -0
- package/themes/ros-pine.js +62 -0
- package/themes/rose-pine-dawn.css +1 -0
- package/themes/rose-pine-dawn.d.ts +1 -0
- package/themes/rose-pine-dawn.js +54 -0
- package/themes/rose-pine-moon.css +1 -0
- package/themes/rose-pine-moon.d.ts +1 -0
- package/themes/rose-pine-moon.js +54 -0
- package/themes/rose-pine.css +1 -0
- package/themes/rose-pine.d.ts +1 -0
- package/themes/rose-pine.js +54 -0
- package/themes/routeros.css +1 -0
- package/themes/routeros.d.ts +1 -0
- package/themes/routeros.js +57 -0
- package/themes/sagelight.css +1 -0
- package/themes/sagelight.d.ts +1 -0
- package/themes/sagelight.js +62 -0
- package/themes/sandcastle.css +1 -0
- package/themes/sandcastle.d.ts +1 -0
- package/themes/sandcastle.js +62 -0
- package/themes/school-book.css +1 -0
- package/themes/school-book.d.ts +1 -0
- package/themes/school-book.js +56 -0
- package/themes/seti-ui.css +1 -0
- package/themes/seti-ui.d.ts +1 -0
- package/themes/seti-ui.js +62 -0
- package/themes/shades-of-purple.css +1 -0
- package/themes/shades-of-purple.d.ts +1 -0
- package/themes/shades-of-purple.js +56 -0
- package/themes/shapeshifter.css +1 -0
- package/themes/shapeshifter.d.ts +1 -0
- package/themes/shapeshifter.js +62 -0
- package/themes/silk-dark.css +1 -0
- package/themes/silk-dark.d.ts +1 -0
- package/themes/silk-dark.js +62 -0
- package/themes/silk-light.css +1 -0
- package/themes/silk-light.d.ts +1 -0
- package/themes/silk-light.js +62 -0
- package/themes/snazzy.css +1 -0
- package/themes/snazzy.d.ts +1 -0
- package/themes/snazzy.js +62 -0
- package/themes/solar-flare-light.css +1 -0
- package/themes/solar-flare-light.d.ts +1 -0
- package/themes/solar-flare-light.js +62 -0
- package/themes/solar-flare.css +1 -0
- package/themes/solar-flare.d.ts +1 -0
- package/themes/solar-flare.js +62 -0
- package/themes/solarized-dark.css +1 -0
- package/themes/solarized-dark.d.ts +1 -0
- package/themes/solarized-dark.js +62 -0
- package/themes/solarized-light.css +1 -0
- package/themes/solarized-light.d.ts +1 -0
- package/themes/solarized-light.js +62 -0
- package/themes/spacemacs.css +1 -0
- package/themes/spacemacs.d.ts +1 -0
- package/themes/spacemacs.js +62 -0
- package/themes/srcery.css +1 -0
- package/themes/srcery.d.ts +1 -0
- package/themes/srcery.js +51 -0
- package/themes/stackoverflow-dark.css +1 -0
- package/themes/stackoverflow-dark.d.ts +1 -0
- package/themes/stackoverflow-dark.js +50 -0
- package/themes/stackoverflow-light.css +1 -0
- package/themes/stackoverflow-light.d.ts +1 -0
- package/themes/stackoverflow-light.js +50 -0
- package/themes/summercamp.css +1 -0
- package/themes/summercamp.d.ts +1 -0
- package/themes/summercamp.js +62 -0
- package/themes/summerfruit-dark.css +1 -0
- package/themes/summerfruit-dark.d.ts +1 -0
- package/themes/summerfruit-dark.js +62 -0
- package/themes/summerfruit-light.css +1 -0
- package/themes/summerfruit-light.d.ts +1 -0
- package/themes/summerfruit-light.js +62 -0
- package/themes/sunburst.css +1 -0
- package/themes/sunburst.d.ts +1 -0
- package/themes/sunburst.js +57 -0
- package/themes/synth-midnight-terminal-dark.css +1 -0
- package/themes/synth-midnight-terminal-dark.d.ts +1 -0
- package/themes/synth-midnight-terminal-dark.js +62 -0
- package/themes/synth-midnight-terminal-light.css +1 -0
- package/themes/synth-midnight-terminal-light.d.ts +1 -0
- package/themes/synth-midnight-terminal-light.js +62 -0
- package/themes/tango.css +1 -0
- package/themes/tango.d.ts +1 -0
- package/themes/tango.js +62 -0
- package/themes/tender.css +1 -0
- package/themes/tender.d.ts +1 -0
- package/themes/tender.js +62 -0
- package/themes/tokyo-night-dark.css +1 -0
- package/themes/tokyo-night-dark.d.ts +1 -0
- package/themes/tokyo-night-dark.js +54 -0
- package/themes/tokyo-night-light.css +1 -0
- package/themes/tokyo-night-light.d.ts +1 -0
- package/themes/tokyo-night-light.js +54 -0
- package/themes/tomorrow-night-blue.css +1 -0
- package/themes/tomorrow-night-blue.d.ts +1 -0
- package/themes/tomorrow-night-blue.js +45 -0
- package/themes/tomorrow-night-bright.css +1 -0
- package/themes/tomorrow-night-bright.d.ts +1 -0
- package/themes/tomorrow-night-bright.js +45 -0
- package/themes/tomorrow-night.css +1 -0
- package/themes/tomorrow-night.d.ts +1 -0
- package/themes/tomorrow-night.js +62 -0
- package/themes/tomorrow.css +1 -0
- package/themes/tomorrow.d.ts +1 -0
- package/themes/tomorrow.js +62 -0
- package/themes/twilight.css +1 -0
- package/themes/twilight.d.ts +1 -0
- package/themes/twilight.js +62 -0
- package/themes/unikitty-dark.css +1 -0
- package/themes/unikitty-dark.d.ts +1 -0
- package/themes/unikitty-dark.js +62 -0
- package/themes/unikitty-light.css +1 -0
- package/themes/unikitty-light.d.ts +1 -0
- package/themes/unikitty-light.js +62 -0
- package/themes/vs.css +1 -0
- package/themes/vs.d.ts +1 -0
- package/themes/vs.js +45 -0
- package/themes/vs2015.css +1 -0
- package/themes/vs2015.d.ts +1 -0
- package/themes/vs2015.js +59 -0
- package/themes/vulcan.css +1 -0
- package/themes/vulcan.d.ts +1 -0
- package/themes/vulcan.js +62 -0
- package/themes/windows-10-light.css +1 -0
- package/themes/windows-10-light.d.ts +1 -0
- package/themes/windows-10-light.js +62 -0
- package/themes/windows-10.css +1 -0
- package/themes/windows-10.d.ts +1 -0
- package/themes/windows-10.js +62 -0
- package/themes/windows-95-light.css +1 -0
- package/themes/windows-95-light.d.ts +1 -0
- package/themes/windows-95-light.js +62 -0
- package/themes/windows-95.css +1 -0
- package/themes/windows-95.d.ts +1 -0
- package/themes/windows-95.js +62 -0
- package/themes/windows-high-contrast-light.css +1 -0
- package/themes/windows-high-contrast-light.d.ts +1 -0
- package/themes/windows-high-contrast-light.js +62 -0
- package/themes/windows-high-contrast.css +1 -0
- package/themes/windows-high-contrast.d.ts +1 -0
- package/themes/windows-high-contrast.js +62 -0
- package/themes/windows-nt-light.css +1 -0
- package/themes/windows-nt-light.d.ts +1 -0
- package/themes/windows-nt-light.js +62 -0
- package/themes/windows-nt.css +1 -0
- package/themes/windows-nt.d.ts +1 -0
- package/themes/windows-nt.js +62 -0
- package/themes/woodland.css +1 -0
- package/themes/woodland.d.ts +1 -0
- package/themes/woodland.js +62 -0
- package/themes/xcode-dusk.css +1 -0
- package/themes/xcode-dusk.d.ts +1 -0
- package/themes/xcode-dusk.js +62 -0
- package/themes/xcode.css +1 -0
- package/themes/xcode.d.ts +1 -0
- package/themes/xcode.js +57 -0
- package/themes/xt256.css +1 -0
- package/themes/xt256.d.ts +1 -0
- package/themes/xt256.js +56 -0
- package/themes/zenburn.css +1 -0
- package/themes/zenburn.d.ts +1 -0
- package/themes/zenburn.js +62 -0
- package/tokenized-document.d.ts +29 -0
- package/tokenized-document.js +263 -0
- package/typewriter-units.d.ts +13 -0
- package/typewriter-units.js +73 -0
package/engine.js
ADDED
|
@@ -0,0 +1,1283 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Highlighting engine (MIT, no highlight.js code). Runs a serializable
|
|
3
|
+
* grammar IR built from hljs grammars by scripts/convert-grammars.ts.
|
|
4
|
+
*
|
|
5
|
+
* Output is a flat scope-event stream. HTML, CSS Custom Highlight ranges, and
|
|
6
|
+
* line-indexed tokens (`renderHtml`, `toRanges`, `tokenLines`) are three
|
|
7
|
+
* renderers over the same events - see the `Renderer` interface exported
|
|
8
|
+
* from engine.d.ts. Tokenizer state is serializable so parses can
|
|
9
|
+
* checkpoint, resume, and stream. Callback behavior from hljs grammars
|
|
10
|
+
* becomes declarative IR flags (endSameAsBegin, onlyAtInputStart,
|
|
11
|
+
* notAfterDot).
|
|
12
|
+
*
|
|
13
|
+
* A well-formed event stream is balanced: every OPEN has a matching later
|
|
14
|
+
* CLOSE, properly nested, and the TEXT values, concatenated in order, equal
|
|
15
|
+
* the tokenized source. All renderers in this module assume this invariant.
|
|
16
|
+
*
|
|
17
|
+
* Scope names stay on hljs's vocabulary (`hljs-*` classes) so existing themes
|
|
18
|
+
* and the CSS-Highlight theme converter keep working. Scope names as they
|
|
19
|
+
* appear in events/tokenLines are the raw, unprefixed strings (e.g.
|
|
20
|
+
* "keyword", "title.class_"); the `hljs-` prefix and multi-class expansion
|
|
21
|
+
* are `renderHtml`'s concern (see `scopeToCssClass`).
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @typedef {import("./engine.d.ts").GrammarIR} GrammarIR
|
|
26
|
+
* @typedef {import("./engine.d.ts").GrammarState} GrammarState
|
|
27
|
+
* @typedef {import("./engine.d.ts").ScopeEvent} ScopeEvent
|
|
28
|
+
* @typedef {import("./engine.d.ts").TokenRange} TokenRange
|
|
29
|
+
* @typedef {import("./engine.d.ts").LineToken} LineToken
|
|
30
|
+
* @typedef {import("./engine.d.ts").HighlightResult} HighlightResult
|
|
31
|
+
* @typedef {import("./engine.d.ts").StreamSession} StreamSession
|
|
32
|
+
* @typedef {import("./engine.d.ts").Registry} Registry
|
|
33
|
+
* @typedef {import("./engine.d.ts").Snapshot} Snapshot
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* A grammar plus its transitive `subLanguage` dependencies, as passed to
|
|
38
|
+
* `registerAll` (e.g. astro's entry lists html/typescript/css/javascript).
|
|
39
|
+
* @typedef {{ name: string, register: GrammarIR, dependencies?: Language[] }} Language
|
|
40
|
+
*/
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A grammar state after `compileProgram` has compiled its string patterns
|
|
44
|
+
* into RegExps (and normalized `keywords`/`relevance` - the IR omits
|
|
45
|
+
* `relevance` when it's the default 1, but the compiled form always has it).
|
|
46
|
+
* @typedef {Omit<GrammarState, "keywords" | "relevance"> & {
|
|
47
|
+
* relevance: number,
|
|
48
|
+
* keywords: Record<string, [string, number]> | null,
|
|
49
|
+
* beginRe: RegExp | null,
|
|
50
|
+
* endRe: RegExp | null,
|
|
51
|
+
* illegalRe: RegExp | null,
|
|
52
|
+
* keywordRe: RegExp | null,
|
|
53
|
+
* }} CompiledState
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* @typedef {{ ir: GrammarIR, states: CompiledState[] }} Program
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Memoized result of scanning a single rule/frame's pattern: `match` is the
|
|
62
|
+
* earliest guard-passing match at or after the position `this.pos` had when
|
|
63
|
+
* it was computed (or `null` if none exists in `this.code` as of `codeLen`
|
|
64
|
+
* characters). See `Tokenizer#cachedMatch`.
|
|
65
|
+
* @typedef {{ codeLen: number, match: RegExpExecArray | null }} MatchCache
|
|
66
|
+
*/
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* One entry of the tokenizer's parse stack. `endCache` memoizes this
|
|
70
|
+
* frame's end-pattern scan (see `cachedMatch`); it's per-frame rather than
|
|
71
|
+
* per-state because `endSameAsBegin`'s guard depends on this frame's own
|
|
72
|
+
* `beginMatch`, and two frames can share the same state (recursive nesting).
|
|
73
|
+
* `beginPos` is this frame's begin match's position in `this.code` (see
|
|
74
|
+
* `subContinuations` below).
|
|
75
|
+
* @typedef {{ idx: number, state: CompiledState, beginMatch: string | undefined, beginPos: number, endCache?: MatchCache }} Frame
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Serializable snapshot of a stack frame (see `Tokenizer#snapshot`).
|
|
80
|
+
* @typedef {{ idx: number, beginMatch: string | undefined, beginPos: number }} FrameSnapshot
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* A sub-language's carried continuation, scoped to one embedding
|
|
85
|
+
* occurrence (see `subContinuations`).
|
|
86
|
+
* @typedef {{ beginPos: number, frames: FrameSnapshot[] }} SubContinuation
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* The subset of the registry's shape that `Tokenizer` itself relies on
|
|
91
|
+
* (embedded-language lookups). The object built by `createRegistry()` has
|
|
92
|
+
* more members than this, but it structurally satisfies it.
|
|
93
|
+
* @typedef {{
|
|
94
|
+
* get(name: string): Program | undefined,
|
|
95
|
+
* tokenizeAuto(code: string, subset?: string[] | null): {
|
|
96
|
+
* language: string | undefined,
|
|
97
|
+
* relevance: number,
|
|
98
|
+
* events: ScopeEvent[],
|
|
99
|
+
* secondBest?: { language: string | undefined, relevance: number },
|
|
100
|
+
* },
|
|
101
|
+
* }} EngineRegistry
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @typedef {{ match: RegExpExecArray, kind: "begin" | "end" | "illegal", data: number | null }} MatchResult
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
const MAX_KEYWORD_HITS = 7;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Max leading characters used for auto-detection scoring. Keyword relevance
|
|
112
|
+
* caps at MAX_KEYWORD_HITS per word, so scanning past a few KB rarely
|
|
113
|
+
* changes the winner but costs O(candidates × length). tokenizeAuto still
|
|
114
|
+
* re-tokenizes the winner over the full `code` before returning.
|
|
115
|
+
*/
|
|
116
|
+
const DETECT_SAMPLE_LIMIT = 8000;
|
|
117
|
+
|
|
118
|
+
// Tokenizer#isTrulyOpeningTag lookaheads.
|
|
119
|
+
const XML_TAG_DEFAULT_PARAM_RE = /^\s*=/;
|
|
120
|
+
const XML_TAG_EXTENDS_CONSTRAINT_RE = /^\s+extends\s+/;
|
|
121
|
+
|
|
122
|
+
/** Event kinds. Events are {t: TEXT, v} | {t: OPEN, s} | {t: CLOSE}. */
|
|
123
|
+
export const TEXT = 0;
|
|
124
|
+
export const OPEN = 1;
|
|
125
|
+
export const CLOSE = 2;
|
|
126
|
+
|
|
127
|
+
/** @param {string} value */
|
|
128
|
+
export function escapeHtml(value) {
|
|
129
|
+
return value
|
|
130
|
+
.replace(/&/g, "&")
|
|
131
|
+
.replace(/</g, "<")
|
|
132
|
+
.replace(/>/g, ">")
|
|
133
|
+
.replace(/"/g, """)
|
|
134
|
+
.replace(/'/g, "'");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Compiles an IR (plain JSON) into an executable program.
|
|
139
|
+
* @param {GrammarIR} ir
|
|
140
|
+
* @returns {Program}
|
|
141
|
+
*/
|
|
142
|
+
function compileProgram(ir) {
|
|
143
|
+
const flags = `mg${ir.caseInsensitive ? "i" : ""}${ir.unicode ? "u" : ""}`;
|
|
144
|
+
/** @param {string | undefined} src */
|
|
145
|
+
const re = (src) => (src == null ? null : new RegExp(src, flags));
|
|
146
|
+
const states = ir.states.map((s) => ({
|
|
147
|
+
...s,
|
|
148
|
+
// Omitted in the shipped IR when it's the default (see convert-language.ts).
|
|
149
|
+
relevance: s.relevance ?? 1,
|
|
150
|
+
keywords: s.keywords
|
|
151
|
+
? Object.assign(Object.create(null), s.keywords)
|
|
152
|
+
: null,
|
|
153
|
+
beginRe: re(s.begin),
|
|
154
|
+
endRe: re(s.end),
|
|
155
|
+
illegalRe: re(s.illegal),
|
|
156
|
+
keywordRe: s.keywords ? re(s.keywordPattern || "\\w+") : null,
|
|
157
|
+
}));
|
|
158
|
+
return { ir, states };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
class Tokenizer {
|
|
162
|
+
/**
|
|
163
|
+
* @param {EngineRegistry} registry
|
|
164
|
+
* @param {Program} program
|
|
165
|
+
* @param {{ detect?: boolean }} [options] `detect` scores relevance and
|
|
166
|
+
* aborts on `illegal` (mirrors hljs auto-detection semantics).
|
|
167
|
+
*/
|
|
168
|
+
constructor(registry, program, { detect = false } = {}) {
|
|
169
|
+
this.registry = registry;
|
|
170
|
+
this.program = program;
|
|
171
|
+
this.detect = detect;
|
|
172
|
+
this.code = "";
|
|
173
|
+
this.pos = 0;
|
|
174
|
+
this.buffer = "";
|
|
175
|
+
this.relevance = 0;
|
|
176
|
+
/** @type {ScopeEvent[]} */
|
|
177
|
+
this.events = [];
|
|
178
|
+
this.openScopes = 0;
|
|
179
|
+
/** @type {Record<string, number>} */
|
|
180
|
+
this.kwHits = Object.create(null);
|
|
181
|
+
/** @type {Frame[]} */
|
|
182
|
+
this.frames = [
|
|
183
|
+
{
|
|
184
|
+
idx: 0,
|
|
185
|
+
// states[0] (the root state) always exists: compileProgram maps
|
|
186
|
+
// ir.states 1:1, and every grammar has a root state.
|
|
187
|
+
state: /** @type {CompiledState} */ (program.states[0]),
|
|
188
|
+
beginMatch: undefined,
|
|
189
|
+
beginPos: 0,
|
|
190
|
+
},
|
|
191
|
+
];
|
|
192
|
+
this.aborted = false;
|
|
193
|
+
this.iterations = 0;
|
|
194
|
+
/**
|
|
195
|
+
* Embedded-language parse state, carried across segments by name - but
|
|
196
|
+
* only for the *same* embedding occurrence (matched by `beginPos`, the
|
|
197
|
+
* code position where that occurrence's frame began). Without the
|
|
198
|
+
* `beginPos` guard, a later, textually unrelated occurrence of the same
|
|
199
|
+
* sub-language name would incorrectly resume from an earlier, already-
|
|
200
|
+
* closed occurrence's leftover frames instead of starting fresh (e.g.
|
|
201
|
+
* two independent markdown fenced blocks that both embed "xml": the
|
|
202
|
+
* second would wrongly inherit the first's still-open-tag state).
|
|
203
|
+
* @type {Record<string, SubContinuation>}
|
|
204
|
+
*/
|
|
205
|
+
this.subContinuations = Object.create(null);
|
|
206
|
+
/**
|
|
207
|
+
* Memoized begin-pattern scans, indexed by state index (see
|
|
208
|
+
* `cachedMatch`). A rule's "next match" is independent of which parent
|
|
209
|
+
* state referenced it, so this is shared across all of them rather than
|
|
210
|
+
* being per-frame like `Frame#endCache`.
|
|
211
|
+
* @type {(MatchCache | undefined)[]}
|
|
212
|
+
*/
|
|
213
|
+
this.beginCache = [];
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/** @returns {Frame} */
|
|
217
|
+
get top() {
|
|
218
|
+
// Root frame (idx 0) is never popped; doEnd stops at depth >= 1.
|
|
219
|
+
return /** @type {Frame} */ (this.frames[this.frames.length - 1]);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// --- emission ---
|
|
223
|
+
|
|
224
|
+
/** @param {string} value */
|
|
225
|
+
text(value) {
|
|
226
|
+
if (value !== "") this.events.push({ t: TEXT, v: value });
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** @param {string} scope */
|
|
230
|
+
open(scope) {
|
|
231
|
+
this.events.push({ t: OPEN, s: scope });
|
|
232
|
+
this.openScopes++;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
close() {
|
|
236
|
+
this.events.push({ t: CLOSE });
|
|
237
|
+
this.openScopes--;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* @param {string} value
|
|
242
|
+
* @param {string} scope
|
|
243
|
+
*/
|
|
244
|
+
emitKeyword(value, scope) {
|
|
245
|
+
if (!value) return;
|
|
246
|
+
this.open(scope);
|
|
247
|
+
this.text(value);
|
|
248
|
+
this.close();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Emits the capture groups of a begin/end match (hljs "multi-class").
|
|
253
|
+
* @param {Record<string, string | null>} captureScopes
|
|
254
|
+
* @param {RegExpExecArray} match
|
|
255
|
+
*/
|
|
256
|
+
emitCaptures(captureScopes, match) {
|
|
257
|
+
for (const key of Object.keys(captureScopes)) {
|
|
258
|
+
const value = match[+key];
|
|
259
|
+
if (value === undefined) continue;
|
|
260
|
+
const scope = captureScopes[key];
|
|
261
|
+
if (scope) this.emitKeyword(value, scope);
|
|
262
|
+
else this.keywordProcess(value, this.top.state);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// --- buffered text ---
|
|
267
|
+
|
|
268
|
+
flush() {
|
|
269
|
+
const state = this.top.state;
|
|
270
|
+
if (state.subLanguage == null) this.keywordProcess(this.buffer, state);
|
|
271
|
+
else this.flushSubLanguage(state);
|
|
272
|
+
this.buffer = "";
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* @param {string} text
|
|
277
|
+
* @param {CompiledState} state
|
|
278
|
+
*/
|
|
279
|
+
keywordProcess(text, state) {
|
|
280
|
+
if (!state.keywords) {
|
|
281
|
+
this.text(text);
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const keywords = state.keywords;
|
|
285
|
+
// keywordRe is always compiled alongside keywords (see compileProgram),
|
|
286
|
+
// so it is non-null whenever `keywords` is set.
|
|
287
|
+
const keywordRe = /** @type {RegExp} */ (state.keywordRe);
|
|
288
|
+
let lastIndex = 0;
|
|
289
|
+
let buf = "";
|
|
290
|
+
keywordRe.lastIndex = 0;
|
|
291
|
+
let match = keywordRe.exec(text);
|
|
292
|
+
while (match) {
|
|
293
|
+
buf += text.substring(lastIndex, match.index);
|
|
294
|
+
const word = this.program.ir.caseInsensitive
|
|
295
|
+
? match[0].toLowerCase()
|
|
296
|
+
: match[0];
|
|
297
|
+
const data = keywords[word];
|
|
298
|
+
if (data) {
|
|
299
|
+
const [kind, keywordRelevance] = data;
|
|
300
|
+
this.text(buf);
|
|
301
|
+
buf = "";
|
|
302
|
+
this.kwHits[word] = (this.kwHits[word] || 0) + 1;
|
|
303
|
+
if (this.kwHits[word] <= MAX_KEYWORD_HITS) {
|
|
304
|
+
this.relevance += keywordRelevance;
|
|
305
|
+
}
|
|
306
|
+
if (kind.startsWith("_")) {
|
|
307
|
+
// relevance-only keyword, not highlighted
|
|
308
|
+
buf += match[0];
|
|
309
|
+
} else {
|
|
310
|
+
this.emitKeyword(match[0], kind);
|
|
311
|
+
}
|
|
312
|
+
} else {
|
|
313
|
+
buf += match[0];
|
|
314
|
+
}
|
|
315
|
+
lastIndex = keywordRe.lastIndex;
|
|
316
|
+
match = keywordRe.exec(text);
|
|
317
|
+
}
|
|
318
|
+
buf += text.substring(lastIndex);
|
|
319
|
+
this.text(buf);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** @param {CompiledState} state */
|
|
323
|
+
flushSubLanguage(state) {
|
|
324
|
+
const text = this.buffer;
|
|
325
|
+
if (text === "") return;
|
|
326
|
+
// flush() only calls this when state.subLanguage != null.
|
|
327
|
+
const subLanguage = /** @type {string | string[]} */ (state.subLanguage);
|
|
328
|
+
/** @type {{ language: string | undefined, relevance: number, events: ScopeEvent[] }} */
|
|
329
|
+
let result;
|
|
330
|
+
if (typeof subLanguage === "string") {
|
|
331
|
+
const program = this.registry.get(subLanguage);
|
|
332
|
+
if (!program) {
|
|
333
|
+
this.text(text);
|
|
334
|
+
return;
|
|
335
|
+
}
|
|
336
|
+
// Later segments of the *same* embedding occurrence resume where the
|
|
337
|
+
// previous segment's parse left off (e.g. still inside an open tag).
|
|
338
|
+
// Guarded by beginPos: a record left by a different, already-closed
|
|
339
|
+
// occurrence of this sub-language must not leak into this one.
|
|
340
|
+
const beginPos = this.top.beginPos;
|
|
341
|
+
const sub = new Tokenizer(this.registry, program);
|
|
342
|
+
sub.code = text;
|
|
343
|
+
const record = this.subContinuations[subLanguage];
|
|
344
|
+
const carried = record?.beginPos === beginPos ? record.frames : undefined;
|
|
345
|
+
if (carried) {
|
|
346
|
+
sub.frames = carried.map((f) => ({
|
|
347
|
+
idx: f.idx,
|
|
348
|
+
// f.idx was produced by this same program's frame indices, so
|
|
349
|
+
// it's always a valid index into program.states.
|
|
350
|
+
state: /** @type {CompiledState} */ (program.states[f.idx]),
|
|
351
|
+
beginMatch: f.beginMatch,
|
|
352
|
+
beginPos: f.beginPos,
|
|
353
|
+
}));
|
|
354
|
+
for (const frame of sub.frames) {
|
|
355
|
+
if (frame.idx !== 0 && frame.state.scope) sub.open(frame.state.scope);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
sub.run();
|
|
359
|
+
const finished = sub.finish();
|
|
360
|
+
this.subContinuations[subLanguage] = {
|
|
361
|
+
beginPos,
|
|
362
|
+
frames: sub.frames.map((f) => ({
|
|
363
|
+
idx: f.idx,
|
|
364
|
+
beginMatch: f.beginMatch,
|
|
365
|
+
beginPos: f.beginPos,
|
|
366
|
+
})),
|
|
367
|
+
};
|
|
368
|
+
result = {
|
|
369
|
+
language: subLanguage,
|
|
370
|
+
relevance: finished.relevance,
|
|
371
|
+
events: finished.events,
|
|
372
|
+
};
|
|
373
|
+
} else {
|
|
374
|
+
result = this.registry.tokenizeAuto(
|
|
375
|
+
text,
|
|
376
|
+
subLanguage.length ? subLanguage : null,
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
if (state.relevance > 0) this.relevance += result.relevance;
|
|
380
|
+
if (result.language) {
|
|
381
|
+
this.open(`language:${result.language}`);
|
|
382
|
+
for (const event of result.events) this.events.push(event);
|
|
383
|
+
this.close();
|
|
384
|
+
} else {
|
|
385
|
+
for (const event of result.events) this.events.push(event);
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
// --- scanning ---
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Finds the earliest valid match of `re` at or after `from`, skipping
|
|
393
|
+
* matches rejected by `guard`.
|
|
394
|
+
* @param {RegExp} re
|
|
395
|
+
* @param {number} from
|
|
396
|
+
* @param {((m: RegExpExecArray) => boolean) | null} guard
|
|
397
|
+
* @returns {RegExpExecArray | null}
|
|
398
|
+
*/
|
|
399
|
+
execValid(re, from, guard) {
|
|
400
|
+
re.lastIndex = from;
|
|
401
|
+
let match = re.exec(this.code);
|
|
402
|
+
while (match) {
|
|
403
|
+
if (!guard || guard(match)) return match;
|
|
404
|
+
if (match.index >= this.code.length) return null;
|
|
405
|
+
re.lastIndex = match.index + 1;
|
|
406
|
+
match = re.exec(this.code);
|
|
407
|
+
}
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Memoized `execValid(re, this.pos, guard)`. Without this, every token
|
|
413
|
+
* boundary re-scans every rule's pattern from scratch. A cached match stays
|
|
414
|
+
* valid until `this.pos` passes it; a cached miss stays valid until the
|
|
415
|
+
* code grows (streaming append).
|
|
416
|
+
* @param {RegExp} re
|
|
417
|
+
* @param {((m: RegExpExecArray) => boolean) | null} guard
|
|
418
|
+
* @param {MatchCache | undefined} cache
|
|
419
|
+
* @returns {MatchCache}
|
|
420
|
+
*/
|
|
421
|
+
cachedMatch(re, guard, cache) {
|
|
422
|
+
if (cache) {
|
|
423
|
+
if (cache.match !== null && cache.match.index >= this.pos) return cache;
|
|
424
|
+
if (cache.match === null && cache.codeLen === this.code.length)
|
|
425
|
+
return cache;
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
codeLen: this.code.length,
|
|
429
|
+
match: this.execValid(re, this.pos, guard),
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
/**
|
|
434
|
+
* @param {CompiledState} state
|
|
435
|
+
* @returns {((m: RegExpExecArray) => boolean) | null}
|
|
436
|
+
*/
|
|
437
|
+
beginGuard(state) {
|
|
438
|
+
if (state.onlyAtInputStart) {
|
|
439
|
+
return (m) => m.index === 0;
|
|
440
|
+
}
|
|
441
|
+
if (state.notAfterDot) {
|
|
442
|
+
return (m) => this.code[m.index - 1] !== ".";
|
|
443
|
+
}
|
|
444
|
+
if (state.xmlTagGuard) {
|
|
445
|
+
return (m) => this.isTrulyOpeningTag(m);
|
|
446
|
+
}
|
|
447
|
+
return null;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* hljs javascript/typescript JSX-vs-generic disambiguation for a `<Foo`
|
|
452
|
+
* match. Re-evaluated when more code arrives so a streaming closing tag
|
|
453
|
+
* still resolves it. See Tokenizer#isTrulyOpeningTag.
|
|
454
|
+
* @param {RegExpExecArray} match
|
|
455
|
+
* @returns {boolean}
|
|
456
|
+
*/
|
|
457
|
+
isTrulyOpeningTag(match) {
|
|
458
|
+
const afterIdx = match.index + match[0].length;
|
|
459
|
+
const nextChar = this.code[afterIdx];
|
|
460
|
+
// `Array<Array<number>>`, `<T, A extends keyof T, V>`
|
|
461
|
+
if (nextChar === "<" || nextChar === ",") return false;
|
|
462
|
+
// `<something>` - only a tag if a matching closing tag exists later on.
|
|
463
|
+
if (
|
|
464
|
+
nextChar === ">" &&
|
|
465
|
+
this.code.indexOf(`</${match[0].slice(1)}`, afterIdx) === -1
|
|
466
|
+
) {
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
const after = this.code.slice(afterIdx);
|
|
470
|
+
// `<T = any>(key?: string) => Modify<`
|
|
471
|
+
if (XML_TAG_DEFAULT_PARAM_RE.test(after)) return false;
|
|
472
|
+
// `<From extends string>`
|
|
473
|
+
if (XML_TAG_EXTENDS_CONSTRAINT_RE.test(after)) return false;
|
|
474
|
+
return true;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* The next lexeme: earliest match wins; ties break by priority (begin
|
|
479
|
+
* rules in order, then ends innermost-first, then illegal).
|
|
480
|
+
* @returns {MatchResult | null}
|
|
481
|
+
*/
|
|
482
|
+
nextMatch() {
|
|
483
|
+
/** @type {RegExpExecArray | null} */
|
|
484
|
+
let best = null;
|
|
485
|
+
let bestPri = Number.POSITIVE_INFINITY;
|
|
486
|
+
/** @type {"begin" | "end" | "illegal" | ""} */
|
|
487
|
+
let bestKind = "";
|
|
488
|
+
/** @type {number | null} */
|
|
489
|
+
let bestData = null;
|
|
490
|
+
/**
|
|
491
|
+
* @param {RegExpExecArray | null} match
|
|
492
|
+
* @param {number} pri
|
|
493
|
+
* @param {"begin" | "end" | "illegal"} kind
|
|
494
|
+
* @param {number | null} data
|
|
495
|
+
*/
|
|
496
|
+
const consider = (match, pri, kind, data) => {
|
|
497
|
+
if (!match) return;
|
|
498
|
+
if (
|
|
499
|
+
best === null ||
|
|
500
|
+
match.index < best.index ||
|
|
501
|
+
(match.index === best.index && pri < bestPri)
|
|
502
|
+
) {
|
|
503
|
+
best = match;
|
|
504
|
+
bestPri = pri;
|
|
505
|
+
bestKind = kind;
|
|
506
|
+
bestData = data;
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
const state = this.top.state;
|
|
511
|
+
for (let i = 0; i < state.rules.length; i++) {
|
|
512
|
+
// rules[i] is in-bounds by the loop condition.
|
|
513
|
+
const ruleIdx = /** @type {number} */ (state.rules[i]);
|
|
514
|
+
const child = /** @type {CompiledState} */ (this.program.states[ruleIdx]);
|
|
515
|
+
const cache = this.cachedMatch(
|
|
516
|
+
// Every state referenced from a `rules` list has a `begin` pattern.
|
|
517
|
+
/** @type {RegExp} */ (child.beginRe),
|
|
518
|
+
this.beginGuard(child),
|
|
519
|
+
this.beginCache[ruleIdx],
|
|
520
|
+
);
|
|
521
|
+
this.beginCache[ruleIdx] = cache;
|
|
522
|
+
consider(cache.match, i, "begin", ruleIdx);
|
|
523
|
+
}
|
|
524
|
+
// End candidates walk outward while `endsWithParent` chains allow.
|
|
525
|
+
let pri = state.rules.length;
|
|
526
|
+
for (let d = this.frames.length - 1; d >= 1; d--) {
|
|
527
|
+
// d ranges over [1, frames.length - 1], always in bounds.
|
|
528
|
+
const frame = /** @type {Frame} */ (this.frames[d]);
|
|
529
|
+
if (frame.state.endRe) {
|
|
530
|
+
const guard = frame.state.endSameAsBegin
|
|
531
|
+
? (/** @type {RegExpExecArray} */ m) => m[1] === frame.beginMatch
|
|
532
|
+
: null;
|
|
533
|
+
const cache = this.cachedMatch(
|
|
534
|
+
frame.state.endRe,
|
|
535
|
+
guard,
|
|
536
|
+
frame.endCache,
|
|
537
|
+
);
|
|
538
|
+
frame.endCache = cache;
|
|
539
|
+
consider(cache.match, pri++, "end", d);
|
|
540
|
+
}
|
|
541
|
+
if (!frame.state.endsWithParent) break;
|
|
542
|
+
}
|
|
543
|
+
if (this.detect && state.illegalRe) {
|
|
544
|
+
consider(
|
|
545
|
+
this.execValid(state.illegalRe, this.pos, null),
|
|
546
|
+
pri + 1,
|
|
547
|
+
"illegal",
|
|
548
|
+
null,
|
|
549
|
+
);
|
|
550
|
+
}
|
|
551
|
+
return best === null
|
|
552
|
+
? null
|
|
553
|
+
: {
|
|
554
|
+
match: best,
|
|
555
|
+
// consider() only assigns bestKind alongside best, so bestKind is
|
|
556
|
+
// never "" once best is non-null.
|
|
557
|
+
kind: /** @type {"begin" | "end" | "illegal"} */ (bestKind),
|
|
558
|
+
data: bestData,
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
// --- state transitions ---
|
|
563
|
+
|
|
564
|
+
/**
|
|
565
|
+
* Enters a state (shared by begin matches and `starts` chaining).
|
|
566
|
+
* @param {number} idx
|
|
567
|
+
* @param {CompiledState} state
|
|
568
|
+
* @param {RegExpExecArray} match
|
|
569
|
+
*/
|
|
570
|
+
enterState(idx, state, match) {
|
|
571
|
+
if (state.scope) this.open(state.scope);
|
|
572
|
+
if (state.wrapScope) {
|
|
573
|
+
this.emitKeyword(this.buffer, state.wrapScope);
|
|
574
|
+
this.buffer = "";
|
|
575
|
+
} else if (state.captureScopes) {
|
|
576
|
+
this.emitCaptures(state.captureScopes, match);
|
|
577
|
+
this.buffer = "";
|
|
578
|
+
}
|
|
579
|
+
this.frames.push({
|
|
580
|
+
idx,
|
|
581
|
+
state,
|
|
582
|
+
beginMatch: state.endSameAsBegin ? match[1] : undefined,
|
|
583
|
+
beginPos: match.index,
|
|
584
|
+
});
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/**
|
|
588
|
+
* @param {RegExpExecArray} match
|
|
589
|
+
* @param {number} idx
|
|
590
|
+
* @returns {number}
|
|
591
|
+
*/
|
|
592
|
+
doBegin(match, idx) {
|
|
593
|
+
// idx comes from nextMatch's "begin" data, which is always a valid
|
|
594
|
+
// program.states index (see the ruleIdx comment above).
|
|
595
|
+
const state = /** @type {CompiledState} */ (this.program.states[idx]);
|
|
596
|
+
const lexeme = match[0];
|
|
597
|
+
if (state.skip) {
|
|
598
|
+
this.buffer += lexeme;
|
|
599
|
+
} else {
|
|
600
|
+
if (state.excludeBegin) this.buffer += lexeme;
|
|
601
|
+
this.flush();
|
|
602
|
+
if (!state.returnBegin && !state.excludeBegin) this.buffer = lexeme;
|
|
603
|
+
}
|
|
604
|
+
this.enterState(idx, state, match);
|
|
605
|
+
return state.returnBegin ? 0 : lexeme.length;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* @param {RegExpExecArray} match
|
|
610
|
+
* @param {number} depth
|
|
611
|
+
* @returns {number}
|
|
612
|
+
*/
|
|
613
|
+
doEnd(match, depth) {
|
|
614
|
+
// `endsParent` extends the ended range outward through parents.
|
|
615
|
+
let d = depth;
|
|
616
|
+
// this.frames[d] is in bounds: d starts at `depth` (a frame index
|
|
617
|
+
// returned by nextMatch) and only decreases while staying > 1.
|
|
618
|
+
while (d > 1 && /** @type {Frame} */ (this.frames[d]).state.endsParent) d--;
|
|
619
|
+
|
|
620
|
+
const origin = this.top.state;
|
|
621
|
+
const lexeme = match[0];
|
|
622
|
+
if (origin.endWrapScope) {
|
|
623
|
+
this.flush();
|
|
624
|
+
this.emitKeyword(lexeme, origin.endWrapScope);
|
|
625
|
+
} else if (origin.endCaptureScopes) {
|
|
626
|
+
this.flush();
|
|
627
|
+
this.emitCaptures(origin.endCaptureScopes, match);
|
|
628
|
+
} else if (origin.skip) {
|
|
629
|
+
this.buffer += lexeme;
|
|
630
|
+
} else {
|
|
631
|
+
if (!(origin.returnEnd || origin.excludeEnd)) this.buffer += lexeme;
|
|
632
|
+
this.flush();
|
|
633
|
+
if (origin.excludeEnd) this.buffer = lexeme;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/** @type {Frame} */
|
|
637
|
+
let popped;
|
|
638
|
+
do {
|
|
639
|
+
// frames.pop() is non-null: the loop condition (frames.length > d,
|
|
640
|
+
// with d >= 1) guarantees at least one element remains before each pop.
|
|
641
|
+
popped = /** @type {Frame} */ (this.frames.pop());
|
|
642
|
+
if (popped.state.scope) this.close();
|
|
643
|
+
if (!popped.state.skip && popped.state.subLanguage == null) {
|
|
644
|
+
this.relevance += popped.state.relevance;
|
|
645
|
+
}
|
|
646
|
+
} while (this.frames.length > d);
|
|
647
|
+
|
|
648
|
+
if (popped.state.starts != null) {
|
|
649
|
+
const startsIdx = popped.state.starts;
|
|
650
|
+
this.enterState(
|
|
651
|
+
startsIdx,
|
|
652
|
+
/** @type {CompiledState} */ (this.program.states[startsIdx]),
|
|
653
|
+
match,
|
|
654
|
+
);
|
|
655
|
+
}
|
|
656
|
+
return origin.returnEnd ? 0 : lexeme.length;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// --- main loop ---
|
|
660
|
+
|
|
661
|
+
/** Consumes as much of `this.code` as possible; resumable after append. */
|
|
662
|
+
run() {
|
|
663
|
+
if (this.aborted) return;
|
|
664
|
+
for (;;) {
|
|
665
|
+
this.iterations++;
|
|
666
|
+
if (this.iterations > 500000) {
|
|
667
|
+
throw new Error(`potential infinite loop (${this.program.ir.name})`);
|
|
668
|
+
}
|
|
669
|
+
const found = this.nextMatch();
|
|
670
|
+
if (!found) break;
|
|
671
|
+
|
|
672
|
+
const framesBefore = this.frames.length;
|
|
673
|
+
const topBefore = this.top;
|
|
674
|
+
this.buffer += this.code.slice(this.pos, found.match.index);
|
|
675
|
+
|
|
676
|
+
let consumed;
|
|
677
|
+
if (found.kind === "illegal") {
|
|
678
|
+
this.aborted = true;
|
|
679
|
+
return;
|
|
680
|
+
} else if (found.kind === "begin") {
|
|
681
|
+
// consider() only passes null data for "illegal"; "begin" always
|
|
682
|
+
// carries the numeric rule index.
|
|
683
|
+
consumed = this.doBegin(
|
|
684
|
+
found.match,
|
|
685
|
+
/** @type {number} */ (found.data),
|
|
686
|
+
);
|
|
687
|
+
} else {
|
|
688
|
+
// Same invariant as above: "end" always carries the numeric depth.
|
|
689
|
+
consumed = this.doEnd(found.match, /** @type {number} */ (found.data));
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
let next = found.match.index + consumed;
|
|
693
|
+
if (
|
|
694
|
+
next === this.pos &&
|
|
695
|
+
this.frames.length === framesBefore &&
|
|
696
|
+
this.top === topBefore
|
|
697
|
+
) {
|
|
698
|
+
// 0-width match made no progress; emit one char and move on
|
|
699
|
+
// (mirrors hljs's badly-behaved-rule recovery).
|
|
700
|
+
this.buffer += this.code.slice(this.pos, this.pos + 1);
|
|
701
|
+
next = this.pos + 1;
|
|
702
|
+
}
|
|
703
|
+
this.pos = next;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
/** @returns {{ relevance: number, events: ScopeEvent[], aborted: boolean }} */
|
|
708
|
+
finish() {
|
|
709
|
+
this.buffer += this.code.slice(this.pos);
|
|
710
|
+
this.pos = this.code.length;
|
|
711
|
+
this.flush();
|
|
712
|
+
while (this.openScopes > 0) this.close();
|
|
713
|
+
return {
|
|
714
|
+
relevance: this.relevance,
|
|
715
|
+
events: this.events,
|
|
716
|
+
aborted: this.aborted,
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
// --- checkpointing ---
|
|
721
|
+
|
|
722
|
+
/**
|
|
723
|
+
* Serializable parse state; everything needed to resume at `pos`.
|
|
724
|
+
* Includes `subContinuations` (embedded-language parse state, e.g. an
|
|
725
|
+
* astro frontmatter's typescript or a markdown fenced code block) - a
|
|
726
|
+
* resumed parse that omitted it would silently restart every embedded
|
|
727
|
+
* sublanguage from scratch instead of continuing it.
|
|
728
|
+
* @returns {Snapshot}
|
|
729
|
+
*/
|
|
730
|
+
snapshot() {
|
|
731
|
+
return {
|
|
732
|
+
pos: this.pos,
|
|
733
|
+
buffer: this.buffer,
|
|
734
|
+
relevance: this.relevance,
|
|
735
|
+
kwHits: { ...this.kwHits },
|
|
736
|
+
frames: this.frames.map((f) => ({
|
|
737
|
+
idx: f.idx,
|
|
738
|
+
beginMatch: f.beginMatch,
|
|
739
|
+
beginPos: f.beginPos,
|
|
740
|
+
})),
|
|
741
|
+
openScopes: this.openScopes,
|
|
742
|
+
eventCount: this.events.length,
|
|
743
|
+
subContinuations: Object.fromEntries(
|
|
744
|
+
Object.entries(this.subContinuations).map(([name, record]) => [
|
|
745
|
+
name,
|
|
746
|
+
{
|
|
747
|
+
beginPos: record.beginPos,
|
|
748
|
+
frames: record.frames.map((f) => ({
|
|
749
|
+
idx: f.idx,
|
|
750
|
+
beginMatch: f.beginMatch,
|
|
751
|
+
beginPos: f.beginPos,
|
|
752
|
+
})),
|
|
753
|
+
},
|
|
754
|
+
]),
|
|
755
|
+
),
|
|
756
|
+
};
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/** @param {Snapshot} snap */
|
|
760
|
+
restore(snap) {
|
|
761
|
+
this.pos = snap.pos;
|
|
762
|
+
this.buffer = snap.buffer;
|
|
763
|
+
this.relevance = snap.relevance;
|
|
764
|
+
this.kwHits = Object.assign(Object.create(null), snap.kwHits);
|
|
765
|
+
this.frames = snap.frames.map((f) => ({
|
|
766
|
+
idx: f.idx,
|
|
767
|
+
// f.idx was captured from this same program's frames by snapshot(),
|
|
768
|
+
// so it's always a valid index into program.states.
|
|
769
|
+
state: /** @type {CompiledState} */ (this.program.states[f.idx]),
|
|
770
|
+
beginMatch: f.beginMatch,
|
|
771
|
+
beginPos: f.beginPos,
|
|
772
|
+
}));
|
|
773
|
+
this.openScopes = snap.openScopes;
|
|
774
|
+
this.events = [];
|
|
775
|
+
this.subContinuations = Object.assign(
|
|
776
|
+
Object.create(null),
|
|
777
|
+
snap.subContinuations,
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// --- renderers ---
|
|
783
|
+
|
|
784
|
+
/**
|
|
785
|
+
* hljs-compatible class for a scope (`hljs-` prefix, tiered scopes).
|
|
786
|
+
* @param {string} name
|
|
787
|
+
* @param {string} prefix
|
|
788
|
+
*/
|
|
789
|
+
function scopeToCssClass(name, prefix) {
|
|
790
|
+
if (name.startsWith("language:")) {
|
|
791
|
+
return name.replace("language:", "language-");
|
|
792
|
+
}
|
|
793
|
+
if (name.includes(".")) {
|
|
794
|
+
const pieces = name.split(".");
|
|
795
|
+
return [
|
|
796
|
+
`${prefix}${pieces.shift()}`,
|
|
797
|
+
...pieces.map((x, i) => `${x}${"_".repeat(i + 1)}`),
|
|
798
|
+
].join(" ");
|
|
799
|
+
}
|
|
800
|
+
return `${prefix}${name}`;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* @param {ScopeEvent[]} events
|
|
805
|
+
* @param {{ classPrefix?: string }} [options]
|
|
806
|
+
* @returns {string} hljs-compatible HTML
|
|
807
|
+
*/
|
|
808
|
+
export function renderHtml(events, { classPrefix = "hljs-" } = {}) {
|
|
809
|
+
let out = "";
|
|
810
|
+
for (const event of events) {
|
|
811
|
+
if (event.t === TEXT) out += escapeHtml(event.v);
|
|
812
|
+
else if (event.t === OPEN) {
|
|
813
|
+
out += `<span class="${scopeToCssClass(event.s, classPrefix)}">`;
|
|
814
|
+
} else out += "</span>";
|
|
815
|
+
}
|
|
816
|
+
return out;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/**
|
|
820
|
+
* Incrementally extends line-rendered HTML from `pendingHtml`/`openScopes`,
|
|
821
|
+
* processing only `newEvents` since the last call. Avoids re-running
|
|
822
|
+
* `renderHtml` + `splitLines` on the whole stream each repaint (O(n²) for
|
|
823
|
+
* long streams). Used by HighlightStream.
|
|
824
|
+
* @param {ScopeEvent[]} newEvents
|
|
825
|
+
* @param {string[]} openScopes
|
|
826
|
+
* @param {string} pendingHtml
|
|
827
|
+
* @param {{ classPrefix?: string }} [options]
|
|
828
|
+
* @returns {{ completedLines: string[], pendingHtml: string, openScopes: string[] }}
|
|
829
|
+
*/
|
|
830
|
+
export function extendLines(
|
|
831
|
+
newEvents,
|
|
832
|
+
openScopes,
|
|
833
|
+
pendingHtml,
|
|
834
|
+
{ classPrefix = "hljs-" } = {},
|
|
835
|
+
) {
|
|
836
|
+
const stack = [...openScopes];
|
|
837
|
+
/** @type {string[]} */
|
|
838
|
+
const completedLines = [];
|
|
839
|
+
const reopenTags = () =>
|
|
840
|
+
stack
|
|
841
|
+
.map((scope) => `<span class="${scopeToCssClass(scope, classPrefix)}">`)
|
|
842
|
+
.join("");
|
|
843
|
+
let current = pendingHtml;
|
|
844
|
+
for (const event of newEvents) {
|
|
845
|
+
if (event.t === OPEN) {
|
|
846
|
+
stack.push(event.s);
|
|
847
|
+
current += `<span class="${scopeToCssClass(event.s, classPrefix)}">`;
|
|
848
|
+
} else if (event.t === CLOSE) {
|
|
849
|
+
stack.pop();
|
|
850
|
+
current += "</span>";
|
|
851
|
+
} else {
|
|
852
|
+
const text = event.v;
|
|
853
|
+
let start = 0;
|
|
854
|
+
for (let i = 0; i < text.length; i++) {
|
|
855
|
+
if (text.charCodeAt(i) === 10) {
|
|
856
|
+
current += escapeHtml(text.slice(start, i));
|
|
857
|
+
current += "</span>".repeat(stack.length);
|
|
858
|
+
completedLines.push(current);
|
|
859
|
+
current = reopenTags();
|
|
860
|
+
start = i + 1;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
current += escapeHtml(text.slice(start));
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
return { completedLines, pendingHtml: current, openScopes: stack };
|
|
867
|
+
}
|
|
868
|
+
|
|
869
|
+
/**
|
|
870
|
+
* Flat scope ranges for the CSS Custom Highlight API. Same shape as the old
|
|
871
|
+
* token-ranges.js. A run of text is painted with its innermost scope;
|
|
872
|
+
* sublanguage wrappers are transparent.
|
|
873
|
+
* @param {ScopeEvent[]} events
|
|
874
|
+
* @returns {TokenRange[]}
|
|
875
|
+
*/
|
|
876
|
+
export function toRanges(events) {
|
|
877
|
+
/** @type {TokenRange[]} */
|
|
878
|
+
const ranges = [];
|
|
879
|
+
/** @type {Array<string | null>} */
|
|
880
|
+
const stack = [];
|
|
881
|
+
let pos = 0;
|
|
882
|
+
for (const event of events) {
|
|
883
|
+
if (event.t === OPEN) {
|
|
884
|
+
stack.push(event.s.startsWith("language:") ? null : event.s);
|
|
885
|
+
} else if (event.t === CLOSE) {
|
|
886
|
+
stack.pop();
|
|
887
|
+
} else {
|
|
888
|
+
const scope = stack[stack.length - 1];
|
|
889
|
+
if (scope != null && event.v.length > 0) {
|
|
890
|
+
ranges.push({ start: pos, end: pos + event.v.length, scope });
|
|
891
|
+
}
|
|
892
|
+
pos += event.v.length;
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
return ranges;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Line-indexed `{ text, scopes }` tokens - the structured alternative to
|
|
900
|
+
* re-splitting `renderHtml`'s output. A single pass over `events`, maintaining
|
|
901
|
+
* the open-scope stack (like `toRanges`) and splitting `TEXT` values on line
|
|
902
|
+
* breaks (like `extendLines`'s HTML splitting).
|
|
903
|
+
*
|
|
904
|
+
* Splits solely on LF (`\n`, code point 10), matching `splitLines`'s behavior
|
|
905
|
+
* on `renderHtml` output (escaping never touches `\n`). CR (`\r`) is not
|
|
906
|
+
* treated specially - for CRLF input, the `\r` lands as the last character of
|
|
907
|
+
* the preceding line's trailing token, exactly where `splitLines` leaves it
|
|
908
|
+
* in the HTML string. A trailing newline in the source yields a trailing
|
|
909
|
+
* empty line, and an empty `events` array yields one empty line - both to
|
|
910
|
+
* match `splitLines("")` / `splitLines`'s unconditional final push.
|
|
911
|
+
* @param {ScopeEvent[]} events
|
|
912
|
+
* @returns {LineToken[][]}
|
|
913
|
+
*/
|
|
914
|
+
export function tokenLines(events) {
|
|
915
|
+
/** @type {LineToken[][]} */
|
|
916
|
+
const lines = [];
|
|
917
|
+
/** @type {LineToken[]} */
|
|
918
|
+
let line = [];
|
|
919
|
+
/** @type {string[]} */
|
|
920
|
+
const stack = [];
|
|
921
|
+
// Recomputed only on OPEN/CLOSE, so adjacent text on the same nesting
|
|
922
|
+
// level (even across separate TEXT events) shares one array reference and
|
|
923
|
+
// can be merged by identity below.
|
|
924
|
+
/** @type {string[]} */
|
|
925
|
+
let scopes = [];
|
|
926
|
+
/** @type {LineToken | null} */
|
|
927
|
+
let lastToken = null;
|
|
928
|
+
|
|
929
|
+
/** @param {string} text */
|
|
930
|
+
const pushText = (text) => {
|
|
931
|
+
if (text === "") return;
|
|
932
|
+
if (lastToken && lastToken.scopes === scopes) {
|
|
933
|
+
lastToken.text += text;
|
|
934
|
+
} else {
|
|
935
|
+
lastToken = { text, scopes };
|
|
936
|
+
line.push(lastToken);
|
|
937
|
+
}
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
for (const event of events) {
|
|
941
|
+
if (event.t === OPEN) {
|
|
942
|
+
stack.push(event.s);
|
|
943
|
+
scopes = stack.slice();
|
|
944
|
+
} else if (event.t === CLOSE) {
|
|
945
|
+
stack.pop();
|
|
946
|
+
scopes = stack.slice();
|
|
947
|
+
} else {
|
|
948
|
+
const text = event.v;
|
|
949
|
+
let start = 0;
|
|
950
|
+
for (let i = 0; i < text.length; i++) {
|
|
951
|
+
if (text.charCodeAt(i) === 10) {
|
|
952
|
+
pushText(text.slice(start, i));
|
|
953
|
+
lines.push(line);
|
|
954
|
+
line = [];
|
|
955
|
+
lastToken = null;
|
|
956
|
+
start = i + 1;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
pushText(text.slice(start));
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
lines.push(line);
|
|
963
|
+
return lines;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
/**
|
|
967
|
+
* @param {{ classPrefix?: string }} [options]
|
|
968
|
+
* @returns {import("./engine.d.ts").Renderer<string>}
|
|
969
|
+
*/
|
|
970
|
+
export function createHtmlRenderer(options) {
|
|
971
|
+
return { render: (events) => renderHtml(events, options) };
|
|
972
|
+
}
|
|
973
|
+
|
|
974
|
+
/** @returns {import("./engine.d.ts").Renderer<TokenRange[]>} */
|
|
975
|
+
export function createRangeRenderer() {
|
|
976
|
+
return { render: toRanges };
|
|
977
|
+
}
|
|
978
|
+
|
|
979
|
+
/** @returns {import("./engine.d.ts").Renderer<LineToken[][]>} */
|
|
980
|
+
export function createLineRenderer() {
|
|
981
|
+
return { render: tokenLines };
|
|
982
|
+
}
|
|
983
|
+
|
|
984
|
+
/**
|
|
985
|
+
* Registers `language` and its `dependencies` (transitive subLanguage refs).
|
|
986
|
+
* Skips languages already registered under their canonical name.
|
|
987
|
+
*
|
|
988
|
+
* Does not use `registry.get(language.name)` as the skip check. `get` resolves
|
|
989
|
+
* aliases, so hljs's "ini" aliasing "toml" could make `get("toml")` look
|
|
990
|
+
* registered when the real toml grammar has not been loaded yet.
|
|
991
|
+
* @param {Registry} registry
|
|
992
|
+
* @param {Language} language
|
|
993
|
+
*/
|
|
994
|
+
export function registerAll(registry, language) {
|
|
995
|
+
const canonicalName = language.name.toLowerCase();
|
|
996
|
+
const existing = registry.get(canonicalName);
|
|
997
|
+
if (existing && existing.ir.name === canonicalName) return;
|
|
998
|
+
registry.register(language.register);
|
|
999
|
+
for (const dependency of language.dependencies || []) {
|
|
1000
|
+
registerAll(registry, dependency);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
// --- registry (public API) ---
|
|
1005
|
+
|
|
1006
|
+
export function createRegistry() {
|
|
1007
|
+
/** @type {Map<string, Program>} */
|
|
1008
|
+
const programs = new Map();
|
|
1009
|
+
/** @type {Map<string, string>} */
|
|
1010
|
+
const aliases = new Map();
|
|
1011
|
+
|
|
1012
|
+
const registry = {
|
|
1013
|
+
/**
|
|
1014
|
+
* Registers a grammar IR (plain JSON, e.g. from convert.js).
|
|
1015
|
+
* @param {GrammarIR} ir
|
|
1016
|
+
* @returns {Program}
|
|
1017
|
+
*/
|
|
1018
|
+
register(ir) {
|
|
1019
|
+
const program = compileProgram(ir);
|
|
1020
|
+
programs.set(ir.name.toLowerCase(), program);
|
|
1021
|
+
for (const alias of ir.aliases || []) {
|
|
1022
|
+
aliases.set(alias.toLowerCase(), ir.name.toLowerCase());
|
|
1023
|
+
}
|
|
1024
|
+
return program;
|
|
1025
|
+
},
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* @param {string} name
|
|
1029
|
+
* @returns {Program | undefined}
|
|
1030
|
+
*/
|
|
1031
|
+
get(name) {
|
|
1032
|
+
const key = (name || "").toLowerCase();
|
|
1033
|
+
const aliasKey = aliases.get(key);
|
|
1034
|
+
return (
|
|
1035
|
+
programs.get(key) ??
|
|
1036
|
+
(aliasKey === undefined ? undefined : programs.get(aliasKey))
|
|
1037
|
+
);
|
|
1038
|
+
},
|
|
1039
|
+
|
|
1040
|
+
/** @returns {string[]} */
|
|
1041
|
+
listLanguages() {
|
|
1042
|
+
return [...programs.keys()];
|
|
1043
|
+
},
|
|
1044
|
+
|
|
1045
|
+
/**
|
|
1046
|
+
* @param {string} code
|
|
1047
|
+
* @param {string} language
|
|
1048
|
+
* @returns {{ language: string, relevance: number, events: ScopeEvent[] }}
|
|
1049
|
+
*/
|
|
1050
|
+
tokenize(code, language) {
|
|
1051
|
+
const program = this.get(language);
|
|
1052
|
+
if (!program) throw new Error(`Unknown language: "${language}"`);
|
|
1053
|
+
const tokenizer = new Tokenizer(this, program);
|
|
1054
|
+
tokenizer.code = code;
|
|
1055
|
+
tokenizer.run();
|
|
1056
|
+
const result = tokenizer.finish();
|
|
1057
|
+
return {
|
|
1058
|
+
language,
|
|
1059
|
+
relevance: result.relevance,
|
|
1060
|
+
events: result.events,
|
|
1061
|
+
};
|
|
1062
|
+
},
|
|
1063
|
+
|
|
1064
|
+
/**
|
|
1065
|
+
* Detection scoring run: aborts on `illegal`, like hljs auto.
|
|
1066
|
+
* @param {string} code
|
|
1067
|
+
* @param {string} language
|
|
1068
|
+
* @returns {{ relevance: number, events: ScopeEvent[] }}
|
|
1069
|
+
*/
|
|
1070
|
+
score(code, language) {
|
|
1071
|
+
const program = this.get(language);
|
|
1072
|
+
if (!program) return { relevance: 0, events: [{ t: TEXT, v: code }] };
|
|
1073
|
+
const tokenizer = new Tokenizer(this, program, { detect: true });
|
|
1074
|
+
tokenizer.code = code;
|
|
1075
|
+
try {
|
|
1076
|
+
tokenizer.run();
|
|
1077
|
+
if (tokenizer.aborted)
|
|
1078
|
+
return { relevance: 0, events: [{ t: TEXT, v: code }] };
|
|
1079
|
+
const result = tokenizer.finish();
|
|
1080
|
+
return { relevance: result.relevance, events: result.events };
|
|
1081
|
+
} catch {
|
|
1082
|
+
return { relevance: 0, events: [{ t: TEXT, v: code }] };
|
|
1083
|
+
}
|
|
1084
|
+
},
|
|
1085
|
+
|
|
1086
|
+
/**
|
|
1087
|
+
* Auto-detection over any registered grammars (customs included).
|
|
1088
|
+
* @param {string} code
|
|
1089
|
+
* @param {string[] | null} [subset]
|
|
1090
|
+
* @returns {{
|
|
1091
|
+
* language: string | undefined,
|
|
1092
|
+
* relevance: number,
|
|
1093
|
+
* events: ScopeEvent[],
|
|
1094
|
+
* secondBest?: { language: string | undefined, relevance: number },
|
|
1095
|
+
* }}
|
|
1096
|
+
*/
|
|
1097
|
+
tokenizeAuto(code, subset) {
|
|
1098
|
+
const candidates = (subset || this.listLanguages()).filter((name) => {
|
|
1099
|
+
const program = this.get(name);
|
|
1100
|
+
return program && !program.ir.disableAutodetect;
|
|
1101
|
+
});
|
|
1102
|
+
const sample =
|
|
1103
|
+
code.length > DETECT_SAMPLE_LIMIT
|
|
1104
|
+
? code.slice(0, DETECT_SAMPLE_LIMIT)
|
|
1105
|
+
: code;
|
|
1106
|
+
/** @type {{ language: string | undefined, relevance: number, events: ScopeEvent[], secondBest?: { language: string | undefined, relevance: number } }} */
|
|
1107
|
+
let best = {
|
|
1108
|
+
language: undefined,
|
|
1109
|
+
relevance: 0,
|
|
1110
|
+
events: [{ t: TEXT, v: code }],
|
|
1111
|
+
};
|
|
1112
|
+
/** @type {{ language: string | undefined, relevance: number, events: ScopeEvent[] } | undefined} */
|
|
1113
|
+
let secondBest;
|
|
1114
|
+
for (const name of candidates) {
|
|
1115
|
+
const scored = this.score(sample, name);
|
|
1116
|
+
const entry = {
|
|
1117
|
+
language: name,
|
|
1118
|
+
relevance: scored.relevance,
|
|
1119
|
+
events: scored.events,
|
|
1120
|
+
};
|
|
1121
|
+
if (this.beats(entry, best, sample)) {
|
|
1122
|
+
secondBest = best.language ? best : secondBest;
|
|
1123
|
+
best = entry;
|
|
1124
|
+
} else if (!secondBest || entry.relevance > secondBest.relevance) {
|
|
1125
|
+
secondBest = entry;
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
if (secondBest) {
|
|
1129
|
+
best.secondBest = {
|
|
1130
|
+
language: secondBest.language,
|
|
1131
|
+
relevance: secondBest.relevance,
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
// Winner was scored on `sample` only; re-tokenize the full `code`.
|
|
1135
|
+
// secondBest relevance stays sample-scored (informational only).
|
|
1136
|
+
if (best.language && sample.length !== code.length) {
|
|
1137
|
+
const full = this.tokenize(code, best.language);
|
|
1138
|
+
best = { ...best, relevance: full.relevance, events: full.events };
|
|
1139
|
+
}
|
|
1140
|
+
return best;
|
|
1141
|
+
},
|
|
1142
|
+
|
|
1143
|
+
/**
|
|
1144
|
+
* Relevance ordering with hljs's supersetOf tie-break.
|
|
1145
|
+
* @param {{ language: string | undefined, relevance: number }} a
|
|
1146
|
+
* @param {{ language: string | undefined, relevance: number }} b
|
|
1147
|
+
* @param {string} _code
|
|
1148
|
+
* @returns {boolean}
|
|
1149
|
+
*/
|
|
1150
|
+
beats(a, b, _code) {
|
|
1151
|
+
if (a.relevance !== b.relevance) return a.relevance > b.relevance;
|
|
1152
|
+
if (a.language && b.language) {
|
|
1153
|
+
const aLang = this.get(a.language);
|
|
1154
|
+
const bLang = this.get(b.language);
|
|
1155
|
+
if (aLang?.ir.supersetOf === b.language) return true;
|
|
1156
|
+
if (bLang?.ir.supersetOf === a.language) return false;
|
|
1157
|
+
}
|
|
1158
|
+
return false; // stable: first candidate wins ties
|
|
1159
|
+
},
|
|
1160
|
+
|
|
1161
|
+
// hljs-shaped conveniences matching svelte-highlight's call sites
|
|
1162
|
+
|
|
1163
|
+
/**
|
|
1164
|
+
* @param {string} code
|
|
1165
|
+
* @param {{ language: string }} options
|
|
1166
|
+
* @returns {HighlightResult}
|
|
1167
|
+
*/
|
|
1168
|
+
highlight(code, { language }) {
|
|
1169
|
+
const result = this.tokenize(code, language);
|
|
1170
|
+
return {
|
|
1171
|
+
language,
|
|
1172
|
+
relevance: result.relevance,
|
|
1173
|
+
value: renderHtml(result.events),
|
|
1174
|
+
events: result.events,
|
|
1175
|
+
};
|
|
1176
|
+
},
|
|
1177
|
+
|
|
1178
|
+
/**
|
|
1179
|
+
* @param {string} code
|
|
1180
|
+
* @param {string[]} [subset]
|
|
1181
|
+
*/
|
|
1182
|
+
highlightAuto(code, subset) {
|
|
1183
|
+
const result = this.tokenizeAuto(code, subset);
|
|
1184
|
+
return {
|
|
1185
|
+
language: result.language,
|
|
1186
|
+
relevance: result.relevance,
|
|
1187
|
+
value: renderHtml(result.events),
|
|
1188
|
+
events: result.events,
|
|
1189
|
+
secondBest: result.secondBest,
|
|
1190
|
+
};
|
|
1191
|
+
},
|
|
1192
|
+
|
|
1193
|
+
/**
|
|
1194
|
+
* @param {string} code
|
|
1195
|
+
* @param {{ language: string }} options
|
|
1196
|
+
* @returns {TokenRange[]}
|
|
1197
|
+
*/
|
|
1198
|
+
tokenizeRanges(code, { language }) {
|
|
1199
|
+
return toRanges(this.tokenize(code, language).events);
|
|
1200
|
+
},
|
|
1201
|
+
|
|
1202
|
+
/**
|
|
1203
|
+
* Streaming session. Appended text is tokenized incrementally; only
|
|
1204
|
+
* complete lines are consumed so line-anchored matches behave as they
|
|
1205
|
+
* will in the final document. `snapshot()`/`resume()` expose the
|
|
1206
|
+
* serializable checkpoint state.
|
|
1207
|
+
*
|
|
1208
|
+
* `options.from` resumes a parse at `snapshot` instead of from scratch.
|
|
1209
|
+
* Used by incremental-tokenize.js: `code` is text already scanned as of
|
|
1210
|
+
* `snapshot.pos`, and further `append()` calls extend it.
|
|
1211
|
+
* @param {string} language
|
|
1212
|
+
* @param {{ from?: { code: string, snapshot: Snapshot } }} [options]
|
|
1213
|
+
* @returns {StreamSession}
|
|
1214
|
+
*/
|
|
1215
|
+
createSession(language, { from } = {}) {
|
|
1216
|
+
const program = this.get(language);
|
|
1217
|
+
if (!program) throw new Error(`Unknown language: "${language}"`);
|
|
1218
|
+
const tokenizer = new Tokenizer(this, program);
|
|
1219
|
+
const registry = this;
|
|
1220
|
+
let staged = "";
|
|
1221
|
+
let fed = from ? from.code : "";
|
|
1222
|
+
if (from) {
|
|
1223
|
+
tokenizer.code = from.code;
|
|
1224
|
+
tokenizer.restore(from.snapshot);
|
|
1225
|
+
}
|
|
1226
|
+
return {
|
|
1227
|
+
/** @param {string} text */
|
|
1228
|
+
append(text) {
|
|
1229
|
+
fed += text;
|
|
1230
|
+
staged += text;
|
|
1231
|
+
const newline = staged.lastIndexOf("\n");
|
|
1232
|
+
if (newline >= 0) {
|
|
1233
|
+
tokenizer.code += staged.slice(0, newline + 1);
|
|
1234
|
+
staged = staged.slice(newline + 1);
|
|
1235
|
+
tokenizer.run();
|
|
1236
|
+
}
|
|
1237
|
+
},
|
|
1238
|
+
/**
|
|
1239
|
+
* Multi-line lookahead (e.g. ruby heredocs) may need the full text
|
|
1240
|
+
* before it can match. `canonicalize` re-tokenizes in one O(n) pass.
|
|
1241
|
+
* @param {{ canonicalize?: boolean }} [options]
|
|
1242
|
+
* @returns {HighlightResult}
|
|
1243
|
+
*/
|
|
1244
|
+
finish({ canonicalize = false } = {}) {
|
|
1245
|
+
if (canonicalize) return registry.highlight(fed, { language });
|
|
1246
|
+
tokenizer.code += staged;
|
|
1247
|
+
staged = "";
|
|
1248
|
+
tokenizer.run();
|
|
1249
|
+
const result = tokenizer.finish();
|
|
1250
|
+
return {
|
|
1251
|
+
language,
|
|
1252
|
+
relevance: result.relevance,
|
|
1253
|
+
events: result.events,
|
|
1254
|
+
value: renderHtml(result.events),
|
|
1255
|
+
};
|
|
1256
|
+
},
|
|
1257
|
+
snapshot: () => tokenizer.snapshot(),
|
|
1258
|
+
events: () => tokenizer.events,
|
|
1259
|
+
};
|
|
1260
|
+
},
|
|
1261
|
+
|
|
1262
|
+
/**
|
|
1263
|
+
* Resumes a parse from a snapshot; emits only post-snapshot events.
|
|
1264
|
+
* @param {string} code
|
|
1265
|
+
* @param {string} language
|
|
1266
|
+
* @param {Snapshot} snap
|
|
1267
|
+
* @returns {{ events: ScopeEvent[], relevance: number }}
|
|
1268
|
+
*/
|
|
1269
|
+
resume(code, language, snap) {
|
|
1270
|
+
const program = this.get(language);
|
|
1271
|
+
// resume() does not validate `language`; unregistered names throw in
|
|
1272
|
+
// Tokenizer when it reads program.states (same as before types).
|
|
1273
|
+
const tokenizer = new Tokenizer(this, /** @type {Program} */ (program));
|
|
1274
|
+
tokenizer.code = code;
|
|
1275
|
+
tokenizer.restore(snap);
|
|
1276
|
+
tokenizer.run();
|
|
1277
|
+
const result = tokenizer.finish();
|
|
1278
|
+
return { events: result.events, relevance: result.relevance };
|
|
1279
|
+
},
|
|
1280
|
+
};
|
|
1281
|
+
|
|
1282
|
+
return registry;
|
|
1283
|
+
}
|