fix(deps): update module github.com/alecthomas/chroma/v2 to v2.20.0 (main) (#18710)

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
pull/17454/head^2
renovate[bot] 10 months ago committed by GitHub
parent f39fc1e6e6
commit c8e87ddfe5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      go.mod
  2. 8
      go.sum
  3. 65
      vendor/github.com/alecthomas/chroma/v2/Dockerfile
  4. 16
      vendor/github.com/alecthomas/chroma/v2/Makefile
  5. 55
      vendor/github.com/alecthomas/chroma/v2/README.md
  6. 6
      vendor/github.com/alecthomas/chroma/v2/biome.json
  7. 9
      vendor/github.com/alecthomas/chroma/v2/delegate.go
  8. 42
      vendor/github.com/alecthomas/chroma/v2/formatters/html/html.go
  9. 17
      vendor/github.com/alecthomas/chroma/v2/lexer.go
  10. 4
      vendor/github.com/alecthomas/chroma/v2/lexers/embedded/css.xml
  11. 13
      vendor/github.com/alecthomas/chroma/v2/lexers/embedded/docker.xml
  12. 83
      vendor/github.com/alecthomas/chroma/v2/lexers/embedded/lox.xml
  13. 121
      vendor/github.com/alecthomas/chroma/v2/lexers/embedded/nu.xml
  14. 9
      vendor/github.com/alecthomas/chroma/v2/lexers/embedded/objectpascal.xml
  15. 1
      vendor/github.com/alecthomas/chroma/v2/lexers/embedded/toml.xml
  16. 37
      vendor/github.com/alecthomas/chroma/v2/lexers/gemtext.go
  17. 8
      vendor/github.com/alecthomas/chroma/v2/lexers/go.go
  18. 6
      vendor/github.com/alecthomas/chroma/v2/lexers/markdown.go
  19. 21
      vendor/github.com/alecthomas/chroma/v2/lexers/raku.go
  20. 36
      vendor/github.com/alecthomas/chroma/v2/regexp.go
  21. 6
      vendor/github.com/alecthomas/chroma/v2/styles/catppuccin-frappe.xml
  22. 6
      vendor/github.com/alecthomas/chroma/v2/styles/catppuccin-latte.xml
  23. 6
      vendor/github.com/alecthomas/chroma/v2/styles/catppuccin-macchiato.xml
  24. 6
      vendor/github.com/alecthomas/chroma/v2/styles/catppuccin-mocha.xml
  25. 2
      vendor/modules.txt

@ -322,7 +322,7 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.3.1 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/alecthomas/chroma/v2 v2.19.0
github.com/alecthomas/chroma/v2 v2.20.0
github.com/alecthomas/units v0.0.0-20240927000941-0f3dac36c52b // indirect
github.com/armon/go-metrics v0.4.1 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect

@ -165,12 +165,12 @@ github.com/Workiva/go-datastructures v1.1.5/go.mod h1:1yZL+zfsztete+ePzZz/Zb1/t5
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/chroma/v2 v2.19.0 h1:Im+SLRgT8maArxv81mULDWN8oKxkzboH07CHesxElq4=
github.com/alecthomas/chroma/v2 v2.19.0/go.mod h1:RVX6AvYm4VfYe/zsk7mjHueLDZor3aWCNE14TFlepBk=
github.com/alecthomas/chroma/v2 v2.20.0 h1:sfIHpxPyR07/Oylvmcai3X/exDlE8+FA820NTz+9sGw=
github.com/alecthomas/chroma/v2 v2.20.0/go.mod h1:e7tViK0xh/Nf4BYHl00ycY6rV7b8iXBksI9E359yNmA=
github.com/alecthomas/kingpin/v2 v2.4.0 h1:f48lwail6p8zpO1bC4TxtqACaGqHYA22qkHjHpqDjYY=
github.com/alecthomas/kingpin/v2 v2.4.0/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/alecthomas/repr v0.5.1 h1:E3G4t2QbHTSNpPKBgMTln5KLkZHLOcU7r37J4pXBuIg=
github.com/alecthomas/repr v0.5.1/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=

@ -0,0 +1,65 @@
# Multi-stage Dockerfile for chromad Go application using Hermit-managed tools
# Build stage
FROM ubuntu:24.04 AS builder
# Install system dependencies
RUN apt-get update && apt-get install -y \
curl \
git \
make \
ca-certificates \
&& rm -rf /var/lib/apt/lists/*
# Set working directory
WORKDIR /app
# Copy the entire project (including bin directory with Hermit tools)
COPY . .
# Make Hermit tools executable and add to PATH
ENV PATH="/app/bin:${PATH}"
# Set Go environment variables for static compilation
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
# Build the application using make
RUN make build/chromad
# Runtime stage
FROM alpine:3.22 AS runtime
# Install ca-certificates for HTTPS requests
RUN apk --no-cache add ca-certificates curl
# Create a non-root user
RUN addgroup -g 1001 chromad && \
adduser -D -s /bin/sh -u 1001 -G chromad chromad
# Set working directory
WORKDIR /app
# Copy the binary from build stage
COPY --from=builder /app/build/chromad /app/chromad
# Change ownership to non-root user
RUN chown chromad:chromad /app/chromad
# Switch to non-root user
USER chromad
# Expose port (default is 8080, but can be overridden via PORT env var)
EXPOSE 8080
# Set default environment variables
ENV PORT=8080
ENV CHROMA_CSRF_KEY="testtest"
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD curl -fsSL http://127.0.0.1:8080/ > /dev/null
# Run the application
CMD ["sh", "-c", "./chromad --csrf-key=$CHROMA_CSRF_KEY --bind=0.0.0.0:$PORT"]

@ -6,12 +6,16 @@ export GOARCH ?= amd64
all: README.md tokentype_string.go
README.md: lexers/*/*.go
./table.py
README.md: lexers/*.go lexers/embedded/*.xml
GOOS= GOARCH= ./table.py
tokentype_string.go: types.go
go generate
.PHONY: format-js
format-js:
biome format --write cmd/chromad/static/{index.js,chroma.js}
.PHONY: chromad
chromad: build/chromad
@ -26,8 +30,12 @@ build/chromad: $(shell find cmd/chromad -name '*.go' -o -name '*.html' -o -name
cmd/chromad/static/wasm_exec.js: $(shell tinygo env TINYGOROOT)/targets/wasm_exec.js
install -m644 $< $@
cmd/chromad/static/chroma.wasm: cmd/libchromawasm/main.go
tinygo build -no-debug -target wasm -o $@ $<
cmd/chromad/static/chroma.wasm: $(shell git ls-files | grep '\.go|\.xml')
if type tinygo > /dev/null; then \
tinygo build -no-debug -target wasm -o $@ cmd/libchromawasm/main.go; \
else \
GOOS=js GOARCH=wasm go build -o $@ cmd/libchromawasm/main.go; \
fi
upload: build/chromad
scp build/chromad root@swapoff.org: && \

@ -34,33 +34,34 @@ translators for Pygments lexers and styles.
## Supported languages
| Prefix | Language |
| :----: | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| A | ABAP, ABNF, ActionScript, ActionScript 3, Ada, Agda, AL, Alloy, Angular2, ANTLR, ApacheConf, APL, AppleScript, ArangoDB AQL, Arduino, ArmAsm, AutoHotkey, AutoIt, Awk |
| B | Ballerina, Bash, Bash Session, Batchfile, BibTeX, Bicep, BlitzBasic, BNF, BQN, Brainfuck |
| C | C, C#, C++, Caddyfile, Caddyfile Directives, Cap'n Proto, Cassandra CQL, Ceylon, CFEngine3, cfstatement, ChaiScript, Chapel, Cheetah, Clojure, CMake, COBOL, CoffeeScript, Common Lisp, Coq, Crystal, CSS, Cython |
| D | D, Dart, Dax, Desktop Entry, Diff, Django/Jinja, dns, Docker, DTD, Dylan |
| E | EBNF, Elixir, Elm, EmacsLisp, Erlang |
| F | Factor, Fennel, Fish, Forth, Fortran, FortranFixed, FSharp |
| G | GAS, GDScript, Genshi, Genshi HTML, Genshi Text, Gherkin, Gleam, GLSL, Gnuplot, Go, Go HTML Template, Go Text Template, GraphQL, Groff, Groovy |
| H | Handlebars, Hare, Haskell, Haxe, HCL, Hexdump, HLB, HLSL, HolyC, HTML, HTTP, Hy |
| I | Idris, Igor, INI, Io, ISCdhcpd |
| J | J, Java, JavaScript, JSON, Jsonnet, Julia, Jungle |
| K | Kotlin |
| L | Lean, Lighttpd configuration file, LLVM, Lua |
| M | Makefile, Mako, markdown, Mason, Materialize SQL dialect, Mathematica, Matlab, MCFunction, Meson, Metal, MiniZinc, MLIR, Modula-2, Mojo, MonkeyC, MorrowindScript, Myghty, MySQL |
| N | NASM, Natural, Newspeak, Nginx configuration file, Nim, Nix, NSIS |
| O | Objective-C, OCaml, Octave, Odin, OnesEnterprise, OpenEdge ABL, OpenSCAD, Org Mode |
| P | PacmanConf, Perl, PHP, PHTML, Pig, PkgConfig, PL/pgSQL, plaintext, Plutus Core, Pony, PostgreSQL SQL dialect, PostScript, POVRay, PowerQuery, PowerShell, Prolog, PromQL, Promela, properties, Protocol Buffer, PRQL, PSL, Puppet, Python, Python 2 |
| Q | QBasic, QML |
| R | R, Racket, Ragel, Raku, react, ReasonML, reg, Rego, reStructuredText, Rexx, RPMSpec, Ruby, Rust |
| S | SAS, Sass, Scala, Scheme, Scilab, SCSS, Sed, Sieve, Smali, Smalltalk, Smarty, SNBT, Snobol, Solidity, SourcePawn, SPARQL, SQL, SquidConf, Standard ML, stas, Stylus, Svelte, Swift, SYSTEMD, systemverilog |
| T | TableGen, Tal, TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, TeX, Thrift, TOML, TradingView, Transact-SQL, Turing, Turtle, Twig, TypeScript, TypoScript, TypoScriptCssData, TypoScriptHtmlData, Typst |
| V | V, V shell, Vala, VB.net, verilog, VHDL, VHS, VimL, vue |
| W | WDTE, WebGPU Shading Language, Whiley |
| X | XML, Xorg |
| Y | YAML, YANG |
| Z | Z80 Assembly, Zed, Zig |
| Prefix | Language
| :----: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| A | ABAP, ABNF, ActionScript, ActionScript 3, Ada, Agda, AL, Alloy, Angular2, ANTLR, ApacheConf, APL, AppleScript, ArangoDB AQL, Arduino, ArmAsm, ATL, AutoHotkey, AutoIt, Awk
| B | Ballerina, Bash, Bash Session, Batchfile, Beef, BibTeX, Bicep, BlitzBasic, BNF, BQN, Brainfuck
| C | C, C#, C++, Caddyfile, Caddyfile Directives, Cap'n Proto, Cassandra CQL, Ceylon, CFEngine3, cfstatement, ChaiScript, Chapel, Cheetah, Clojure, CMake, COBOL, CoffeeScript, Common Lisp, Coq, Core, Crystal, CSS, CSV, CUE, Cython
| D | D, Dart, Dax, Desktop file, Diff, Django/Jinja, dns, Docker, DTD, Dylan
| E | EBNF, Elixir, Elm, EmacsLisp, Erlang
| F | Factor, Fennel, Fish, Forth, Fortran, FortranFixed, FSharp
| G | GAS, GDScript, GDScript3, Gemtext, Genshi, Genshi HTML, Genshi Text, Gherkin, Gleam, GLSL, Gnuplot, Go, Go HTML Template, Go Template, Go Text Template, GraphQL, Groff, Groovy
| H | Handlebars, Hare, Haskell, Haxe, HCL, Hexdump, HLB, HLSL, HolyC, HTML, HTTP, Hy
| I | Idris, Igor, INI, Io, ISCdhcpd
| J | J, Janet, Java, JavaScript, JSON, JSONata, Jsonnet, Julia, Jungle
| K | Kotlin
| L | Lean4, Lighttpd configuration file, LLVM, lox, Lua
| M | Makefile, Mako, markdown, Mason, Materialize SQL dialect, Mathematica, Matlab, MCFunction, Meson, Metal, MiniZinc, MLIR, Modula-2, Mojo, MonkeyC, MoonScript, MorrowindScript, Myghty, MySQL
| N | NASM, Natural, NDISASM, Newspeak, Nginx configuration file, Nim, Nix, NSIS, Nu
| O | Objective-C, ObjectPascal, OCaml, Octave, Odin, OnesEnterprise, OpenEdge ABL, OpenSCAD, Org Mode
| P | PacmanConf, Perl, PHP, PHTML, Pig, PkgConfig, PL/pgSQL, plaintext, Plutus Core, Pony, PostgreSQL SQL dialect, PostScript, POVRay, PowerQuery, PowerShell, Prolog, Promela, PromQL, properties, Protocol Buffer, PRQL, PSL, Puppet, Python, Python 2
| Q | QBasic, QML
| R | R, Racket, Ragel, Raku, react, ReasonML, reg, Rego, reStructuredText, Rexx, RPGLE, RPMSpec, Ruby, Rust
| S | SAS, Sass, Scala, Scheme, Scilab, SCSS, Sed, Sieve, Smali, Smalltalk, Smarty, SNBT, Snobol, Solidity, SourcePawn, SPARQL, SQL, SquidConf, Standard ML, stas, Stylus, Svelte, Swift, SYSTEMD, systemverilog
| T | TableGen, Tal, TASM, Tcl, Tcsh, Termcap, Terminfo, Terraform, TeX, Thrift, TOML, TradingView, Transact-SQL, Turing, Turtle, Twig, TypeScript, TypoScript, TypoScriptCssData, TypoScriptHtmlData, Typst
| U | ucode
| V | V, V shell, Vala, VB.net, verilog, VHDL, VHS, VimL, vue
| W | WDTE, WebGPU Shading Language, WebVTT, Whiley
| X | XML, Xorg
| Y | YAML, YANG
| Z | Z80 Assembly, Zed, Zig
_I will attempt to keep this section up to date, but an authoritative list can be
displayed with `chroma --list`._

@ -0,0 +1,6 @@
{
"$schema": "https://biomejs.dev/schemas/2.0.5/schema.json",
"formatter": {
"indentStyle": "space"
}
}

@ -24,6 +24,15 @@ func DelegatingLexer(root Lexer, language Lexer) Lexer {
}
}
func (d *delegatingLexer) SetTracing(enable bool) {
if l, ok := d.language.(TracingLexer); ok {
l.SetTracing(enable)
}
if l, ok := d.root.(TracingLexer); ok {
l.SetTracing(enable)
}
}
func (d *delegatingLexer) AnalyseText(text string) float32 {
return d.root.AnalyseText(text)
}

@ -34,6 +34,9 @@ func WithCustomCSS(css map[chroma.TokenType]string) Option {
}
}
// WithCSSComments adds prefixe comments to the css classes. Defaults to true.
func WithCSSComments(b bool) Option { return func(f *Formatter) { f.writeCSSComments = b } }
// TabWidth sets the number of characters for a tab. Defaults to 8.
func TabWidth(width int) Option { return func(f *Formatter) { f.tabWidth = width } }
@ -131,8 +134,9 @@ func BaseLineNumber(n int) Option {
// New HTML formatter.
func New(options ...Option) *Formatter {
f := &Formatter{
baseLineNumber: 1,
preWrapper: defaultPreWrapper,
baseLineNumber: 1,
preWrapper: defaultPreWrapper,
writeCSSComments: true,
}
f.styleCache = newStyleCache(f)
for _, option := range options {
@ -197,6 +201,7 @@ type Formatter struct {
Classes bool // Exported field to detect when classes are being used
allClasses bool
customCSS map[chroma.TokenType]string
writeCSSComments bool
preWrapper PreWrapper
inlineCode bool
preventSurroundingPre bool
@ -416,21 +421,37 @@ func (f *Formatter) tabWidthStyle() string {
return ""
}
func (f *Formatter) writeCSSRule(w io.Writer, comment string, selector string, styles string) error {
if styles == "" {
return nil
}
if f.writeCSSComments && comment != "" {
if _, err := fmt.Fprintf(w, "/* %s */ ", comment); err != nil {
return err
}
}
if _, err := fmt.Fprintf(w, "%s { %s }\n", selector, styles); err != nil {
return err
}
return nil
}
// WriteCSS writes CSS style definitions (without any surrounding HTML).
func (f *Formatter) WriteCSS(w io.Writer, style *chroma.Style) error {
css := f.styleCache.get(style, false)
// Special-case background as it is mapped to the outer ".chroma" class.
if _, err := fmt.Fprintf(w, "/* %s */ .%sbg { %s }\n", chroma.Background, f.prefix, css[chroma.Background]); err != nil {
if err := f.writeCSSRule(w, chroma.Background.String(), fmt.Sprintf(".%sbg", f.prefix), css[chroma.Background]); err != nil {
return err
}
// Special-case PreWrapper as it is the ".chroma" class.
if _, err := fmt.Fprintf(w, "/* %s */ .%schroma { %s }\n", chroma.PreWrapper, f.prefix, css[chroma.PreWrapper]); err != nil {
if err := f.writeCSSRule(w, chroma.PreWrapper.String(), fmt.Sprintf(".%schroma", f.prefix), css[chroma.PreWrapper]); err != nil {
return err
}
// Special-case code column of table to expand width.
if f.lineNumbers && f.lineNumbersInTable {
if _, err := fmt.Fprintf(w, "/* %s */ .%schroma .%s:last-child { width: 100%%; }",
chroma.LineTableTD, f.prefix, f.class(chroma.LineTableTD)); err != nil {
selector := fmt.Sprintf(".%schroma .%s:last-child", f.prefix, f.class(chroma.LineTableTD))
if err := f.writeCSSRule(w, chroma.LineTableTD.String(), selector, "width: 100%;"); err != nil {
return err
}
}
@ -438,7 +459,11 @@ func (f *Formatter) WriteCSS(w io.Writer, style *chroma.Style) error {
if f.lineNumbers || f.lineNumbersInTable {
targetedLineCSS := StyleEntryToCSS(style.Get(chroma.LineHighlight))
for _, tt := range []chroma.TokenType{chroma.LineNumbers, chroma.LineNumbersTable} {
fmt.Fprintf(w, "/* %s targeted by URL anchor */ .%schroma .%s:target { %s }\n", tt, f.prefix, f.class(tt), targetedLineCSS)
comment := fmt.Sprintf("%s targeted by URL anchor", tt)
selector := fmt.Sprintf(".%schroma .%s:target", f.prefix, f.class(tt))
if err := f.writeCSSRule(w, comment, selector, targetedLineCSS); err != nil {
return err
}
}
}
tts := []int{}
@ -456,8 +481,7 @@ func (f *Formatter) WriteCSS(w io.Writer, style *chroma.Style) error {
if class == "" {
continue
}
styles := css[tt]
if _, err := fmt.Fprintf(w, "/* %s */ .%schroma .%s { %s }\n", tt, f.prefix, class, styles); err != nil {
if err := f.writeCSSRule(w, tt.String(), fmt.Sprintf(".%schroma .%s", f.prefix, class), css[tt]); err != nil {
return err
}
}

@ -130,6 +130,23 @@ type Lexer interface {
AnalyseText(text string) float32
}
// Trace is the trace of a tokenisation process.
type Trace struct {
Lexer string `json:"lexer"`
State string `json:"state"`
Rule int `json:"rule"`
Pattern string `json:"pattern"`
Pos int `json:"pos"`
Length int `json:"length"`
Elapsed float64 `json:"elapsedMs"` // Elapsed time spent matching for this rule.
}
// TracingLexer is a Lexer that can trace its tokenisation process.
type TracingLexer interface {
Lexer
SetTracing(enable bool)
}
// Lexers is a slice of lexers sortable by name.
type Lexers []Lexer

File diff suppressed because one or more lines are too long

@ -3,10 +3,14 @@
<name>Docker</name>
<alias>docker</alias>
<alias>dockerfile</alias>
<alias>containerfile</alias>
<filename>Dockerfile</filename>
<filename>Dockerfile.*</filename>
<filename>*.Dockerfile</filename>
<filename>*.docker</filename>
<filename>Containerfile</filename>
<filename>Containerfile.*</filename>
<filename>*.Containerfile</filename>
<mime_type>text/x-dockerfile-config</mime_type>
<case_insensitive>true</case_insensitive>
</config>
@ -40,9 +44,16 @@
<using lexer="Bash" />
</bygroups>
</rule>
<rule pattern="((?:FROM|MAINTAINER|EXPOSE|WORKDIR|USER|STOPSIGNAL)|VOLUME)\b(.*)">
<rule
pattern="((?:FROM|MAINTAINER|EXPOSE|WORKDIR|USER|STOPSIGNAL)|VOLUME)\b(\s)([\S]*)\b(?:(\s)(AS)\b(\s)([\S]*))?\b"
>
<bygroups>
<token type="Keyword" />
<token type="TextWhitespace" />
<token type="LiteralString" />
<token type="TextWhitespace" />
<token type="Keyword" />
<token type="TextWhitespace" />
<token type="LiteralString" />
</bygroups>
</rule>

@ -0,0 +1,83 @@
<lexer>
<config>
<name>lox</name>
<filename>*.lox</filename>
<dot_all>true</dot_all>
<ensure_nl>true</ensure_nl>
</config>
<rules>
<state name="classname">
<rule pattern="[a-zA-Z_]\w*">
<token type="NameClass"/>
<pop depth="1"/>
</rule>
</state>
<state name="funname">
<rule pattern="[a-zA-Z_]\w*">
<token type="NameFunction"/>
<pop depth="1"/>
</rule>
</state>
<state name="varname">
<rule pattern="[a-zA-Z_]\w*">
<token type="NameVariable"/>
<pop depth="1"/>
</rule>
</state>
<state name="whitespace">
<rule pattern="\n">
<token type="Text"/>
</rule>
<rule pattern="\s+">
<token type="Text"/>
</rule>
</state>
<state name="root">
<rule>
<include state="whitespace"/>
</rule>
<rule pattern="//.*?\n">
<token type="CommentSingle"/>
</rule>
<rule pattern="(and|else|for|if|or|print|return|super|this|while)\b">
<token type="Keyword"/>
</rule>
<rule pattern="(false|nil|true)\b">
<token type="KeywordConstant"/>
</rule>
<rule pattern="(class)(\s*)">
<token type="KeywordDeclaration"/>
<push state="classname"/>
</rule>
<rule pattern="(fun)(\s*)">
<token type="KeywordDeclaration"/>
<push state="funname"/>
</rule>
<rule pattern="(var)(\s*)">
<token type="KeywordDeclaration"/>
<push state="varname"/>
</rule>
<rule pattern="\d+(\.\d*|[eE][+\-]?\d+)">
<token type="LiteralNumberFloat"/>
</rule>
<rule pattern="[0-9][0-9]*">
<token type="LiteralNumberInteger"/>
</rule>
<rule pattern="&#34;(\\\\|\\&#34;|[^&#34;])*&#34;">
<token type="LiteralStringDouble"/>
</rule>
<rule pattern="!|\+|-|\*|/|&lt;|&gt;|=">
<token type="Operator"/>
</rule>
<rule pattern="[{(;,]">
<token type="Punctuation"/>
</rule>
<rule pattern="[}).]">
<token type="Punctuation"/>
</rule>
<rule pattern="[a-zA-Z_]\w*">
<token type="NameVariable"/>
</rule>
</state>
</rules>
</lexer>

@ -0,0 +1,121 @@
<lexer>
<config>
<name>Nu</name>
<alias>nu</alias>
<filename>*.nu</filename>
<mime_type>text/plain</mime_type>
</config>
<rules>
<state name="root">
<rule><include state="basic" /></rule>
<rule><include state="data" /></rule>
</state>
<state name="basic">
<rule
pattern="\b(alias|all|ansi|ansi gradient|ansi link|ansi strip|any|append|ast|attr category|attr deprecated|attr example|attr search-terms|banner|bits|bits and|bits not|bits or|bits rol|bits ror|bits shl|bits shr|bits xor|break|bytes|bytes add|bytes at|bytes build|bytes collect|bytes ends-with|bytes index-of|bytes length|bytes remove|bytes replace|bytes reverse|bytes split|bytes starts-with|cal|cd|char|chunk-by|chunks|clear|collect|columns|commandline|commandline edit|commandline get-cursor|commandline set-cursor|compact|complete|config|config env|config flatten|config nu|config reset|config use-colors|const|continue|cp|date|date format|date from-human|date humanize|date list-timezone|date now|date to-timezone|debug|debug env|debug info|debug profile|decode|decode base32|decode base32hex|decode base64|decode hex|def|default|describe|detect columns|do|drop|drop column|drop nth|du|each|each while|echo|encode|encode base32|encode base32hex|encode base64|encode hex|enumerate|error make|every|exec|exit|explain|explore|export|export alias|export const|export def|export extern|export module|export use|export-env|extern|fill|filter|find|first|flatten|for|format|format bits|format date|format duration|format filesize|format number|format pattern|from|from csv|from json|from msgpack|from msgpackz|from nuon|from ods|from ssv|from toml|from tsv|from url|from xlsx|from xml|from yaml|from yml|generate|get|glob|grid|group-by|hash|hash md5|hash sha256|headers|help|help aliases|help commands|help escapes|help externs|help modules|help operators|help pipe-and-redirect|hide|hide-env|histogram|history|history import|history session|http|http delete|http get|http head|http options|http patch|http post|http put|if|ignore|input|input list|input listen|insert|inspect|interleave|into|into binary|into bool|into cell-path|into datetime|into duration|into filesize|into float|into glob|into int|into record|into sqlite|into string|into value|is-admin|is-empty|is-not-empty|is-terminal|items|job|job flush|job id|job kill|job list|job recv|job send|job spawn|job tag|job unfreeze|join|keybindings|keybindings default|keybindings list|keybindings listen|kill|last|length|let|let-env|lines|load-env|loop|ls|match|math|math abs|math arccos|math arccosh|math arcsin|math arcsinh|math arctan|math arctanh|math avg|math ceil|math cos|math cosh|math exp|math floor|math ln|math log|math max|math median|math min|math mode|math product|math round|math sin|math sinh|math sqrt|math stddev|math sum|math tan|math tanh|math variance|merge|merge deep|metadata|metadata access|metadata set|mkdir|mktemp|module|move|mut|mv|nu-check|nu-highlight|open|overlay|overlay hide|overlay list|overlay new|overlay use|panic|par-each|parse|path|path basename|path dirname|path exists|path expand|path join|path parse|path relative-to|path self|path split|path type|plugin|plugin add|plugin list|plugin rm|plugin stop|plugin use|port|prepend|print|ps|pwd|query db|random|random binary|random bool|random chars|random dice|random float|random int|random uuid|reduce|reject|rename|return|reverse|rm|roll|roll down|roll left|roll right|roll up|rotate|run-external|save|schema|scope|scope aliases|scope commands|scope engine-stats|scope externs|scope modules|scope variables|select|seq|seq char|seq date|shuffle|skip|skip until|skip while|sleep|slice|sort|sort-by|source|source-env|split|split cell-path|split chars|split column|split list|split row|split words|start|stor|stor create|stor delete|stor export|stor import|stor insert|stor open|stor reset|stor update|str|str camel-case|str capitalize|str contains|str distance|str downcase|str ends-with|str expand|str index-of|str join|str kebab-case|str length|str pascal-case|str replace|str reverse|str screaming-snake-case|str snake-case|str starts-with|str stats|str substring|str title-case|str trim|str upcase|sys|sys cpu|sys disks|sys host|sys mem|sys net|sys temp|sys users|table|take|take until|take while|tee|term|term query|term size|timeit|to|to csv|to html|to json|to md|to msgpack|to msgpackz|to nuon|to text|to toml|to tsv|to xml|to yaml|to yml|touch|transpose|try|tutor|ulimit|uname|uniq|uniq-by|update|update cells|upsert|url|url build-query|url decode|url encode|url join|url parse|url split-query|use|values|version|version check|view|view blocks|view files|view ir|view source|view span|watch|where|which|while|whoami|window|with-env|wrap|zip)(\s*)\b"
><bygroups><token type="Keyword" /><token
type="TextWhitespace"
/></bygroups></rule>
<rule pattern="\A#!.+\n"><token type="CommentHashbang" /></rule>
<rule pattern="#.*\n"><token type="CommentSingle" /></rule>
<rule pattern="\\[\w\W]"><token type="LiteralStringEscape" /></rule>
<rule pattern="(\b\w+)(\s*)(\+?=)"><bygroups><token
type="NameVariable"
/><token type="TextWhitespace" /><token
type="Operator"
/></bygroups></rule>
<rule pattern="[\[\]{}()=]"><token type="Operator" /></rule>
<rule pattern="&lt;&lt;&lt;"><token type="Operator" /></rule>
<rule pattern="&lt;&lt;-?\s*(\&#x27;?)\\?(\w+)[\w\W]+?\2"><token
type="LiteralString"
/></rule>
<rule pattern="&amp;&amp;|\|\|"><token type="Operator" /></rule>
<rule pattern="\$[a-zA-Z_]\w*"><token type="NameVariable" /></rule>
</state>
<state name="data">
<rule pattern="\$&quot;"><token type="LiteralStringDouble" /><push
state="interpolated_string"
/></rule>
<rule pattern="(?s)&quot;(\\.|[^&quot;\\])*&quot;"><token
type="LiteralStringDouble"
/></rule>
<rule pattern="&quot;"><token type="LiteralStringDouble" /><push
state="string"
/></rule>
<rule pattern="(?s)\$&#x27;(\\\\|\\[0-7]+|\\.|[^&#x27;\\])*&#x27;"><token
type="LiteralStringSingle"
/></rule>
<rule pattern="(?s)&#x27;.*?&#x27;"><token
type="LiteralStringSingle"
/></rule>
<rule pattern=";"><token type="Punctuation" /></rule>
<rule pattern="&amp;"><token type="Punctuation" /></rule>
<rule pattern="\|"><token type="Punctuation" /></rule>
<rule pattern="\s+"><token type="TextWhitespace" /></rule>
<rule pattern="\d+\b"><token type="LiteralNumber" /></rule>
<rule pattern="[^=\s\[\]{}()$&quot;\&#x27;`\\&lt;&amp;|;]+"><token
type="Text"
/></rule>
<rule pattern="&lt;"><token type="Text" /></rule>
</state>
<state name="string">
<rule pattern="&quot;"><token type="LiteralStringDouble" /><pop
depth="1"
/></rule>
<rule pattern="(?s)(\\\\|\\[0-7]+|\\.|[^&quot;\\$])+"><token
type="LiteralStringDouble"
/></rule>
</state>
<state name="interpolated_string">
<rule pattern="&quot;"><token type="LiteralStringDouble" /><pop
depth="1"
/></rule>
<rule pattern="\("><token type="LiteralStringInterpol" /><push
state="interpolation"
/></rule>
<rule pattern="(?s)(\\\\|\\[0-7]+|\\.|[^&quot;\\(])+"><token
type="LiteralStringDouble"
/></rule>
</state>
<state name="interpolation">
<rule pattern="\)"><token type="LiteralStringInterpol" /><pop
depth="1"
/></rule>
<rule><include state="root" /></rule>
</state>
<state name="curly">
<rule pattern="\}"><token type="LiteralStringInterpol" /><pop
depth="1"
/></rule>
<rule pattern=":-"><token type="Keyword" /></rule>
<rule pattern="\w+"><token type="NameVariable" /></rule>
<rule pattern="[^}:&quot;\&#x27;`$\\]+"><token
type="Punctuation"
/></rule>
<rule pattern=":"><token type="Punctuation" /></rule>
<rule><include state="root" /></rule>
</state>
<state name="paren">
<rule pattern="\)"><token type="Keyword" /><pop depth="1" /></rule>
<rule><include state="root" /></rule>
</state>
<state name="math">
<rule pattern="\)\)"><token type="Keyword" /><pop depth="1" /></rule>
<rule pattern="\*\*|\|\||&lt;&lt;|&gt;&gt;|[-+*/%^|&amp;&lt;&gt;]"><token
type="Operator"
/></rule>
<rule pattern="\d+#[\da-zA-Z]+"><token type="LiteralNumber" /></rule>
<rule pattern="\d+#(?! )"><token type="LiteralNumber" /></rule>
<rule pattern="0[xX][\da-fA-F]+"><token type="LiteralNumber" /></rule>
<rule pattern="\d+"><token type="LiteralNumber" /></rule>
<rule pattern="[a-zA-Z_]\w*"><token type="NameVariable" /></rule>
<rule><include state="root" /></rule>
</state>
<state name="backticks">
<rule pattern="`"><token type="LiteralStringBacktick" /><pop
depth="1"
/></rule>
<rule><include state="root" /></rule>
</state>
</rules>
</lexer>

@ -31,12 +31,9 @@
<rule pattern="\{[$].*?\}|\{[-](NOD|EXT|OBJ).*?\}|\([*][$].*?[*]\)">
<token type="CommentPreproc" />
</rule>
<!-- Comment Single -->
<rule pattern="(//.*?)(\n)">
<bygroups>
<token type="CommentSingle" />
<token type="TextWhitespace" />
</bygroups>
<!-- Comment -->
<rule pattern="//.*">
<token type="CommentSingle" />
</rule>
<!-- Comment Multiline Block -->
<rule pattern="\([*](.|\n)*?[*]\)">

@ -5,6 +5,7 @@
<filename>*.toml</filename>
<filename>Pipfile</filename>
<filename>poetry.lock</filename>
<filename>uv.lock</filename>
<mime_type>text/x-toml</mime_type>
</config>
<rules>

@ -0,0 +1,37 @@
package lexers
import (
. "github.com/alecthomas/chroma/v2" // nolint
)
// Gemtext lexer.
var Gemtext = Register(MustNewLexer(
&Config{
Name: "Gemtext",
Aliases: []string{"gemtext", "gmi", "gmni", "gemini"},
Filenames: []string{"*.gmi", "*.gmni", "*.gemini"},
MimeTypes: []string{"text/gemini"},
},
gemtextRules,
))
func gemtextRules() Rules {
return Rules{
"root": {
{`^(#[^#].+\r?\n)`, ByGroups(GenericHeading), nil},
{`^(#{2,3}.+\r?\n)`, ByGroups(GenericSubheading), nil},
{`^(\* )(.+\r?\n)`, ByGroups(Keyword, Text), nil},
{`^(>)(.+\r?\n)`, ByGroups(Keyword, GenericEmph), nil},
{"^(```\\r?\\n)([\\w\\W]*?)(^```)(.+\\r?\\n)?", ByGroups(String, Text, String, Comment), nil},
{
"^(```)(\\w+)(\\r?\\n)([\\w\\W]*?)(^```)(.+\\r?\\n)?",
UsingByGroup(2, 4, String, String, String, Text, String, Comment),
nil,
},
{"^(```)(.+\\r?\\n)([\\w\\W]*?)(^```)(.+\\r?\\n)?", ByGroups(String, String, Text, String, Comment), nil},
{`^(=>)(\s*)([^\s]+)(\s*)$`, ByGroups(Keyword, Text, NameAttribute, Text), nil},
{`^(=>)(\s*)([^\s]+)(\s+)(.+)$`, ByGroups(Keyword, Text, NameAttribute, Text, NameTag), nil},
{`(.|(?:\r?\n))`, ByGroups(Text), nil},
},
}
}

@ -28,10 +28,10 @@ var Go = Register(MustNewLexer(
func goRules() Rules {
return Rules{
"root": {
{`\n`, Text, nil},
{`\s+`, Text, nil},
{`\\\n`, Text, nil},
{`//[^\n\r]*`, CommentSingle, nil},
{`\n`, TextWhitespace, nil},
{`\s+`, TextWhitespace, nil},
{`//[^\s][^\n\r]*`, CommentPreproc, nil},
{`//\s+[^\n\r]*`, CommentSingle, nil},
{`/(\\\n)?[*](.|\n)*?[*](\\\n)?/`, CommentMultiline, nil},
{`(import|package)\b`, KeywordNamespace, nil},
{`(var|func|struct|map|chan|type|interface|const)\b`, KeywordDeclaration, nil},

@ -5,7 +5,7 @@ import (
)
// Markdown lexer.
var Markdown = Register(DelegatingLexer(HTML, MustNewLexer(
var Markdown = Register(MustNewLexer(
&Config{
Name: "markdown",
Aliases: []string{"md", "mkd"},
@ -13,7 +13,7 @@ var Markdown = Register(DelegatingLexer(HTML, MustNewLexer(
MimeTypes: []string{"text/x-markdown"},
},
markdownRules,
)))
))
func markdownRules() Rules {
return Rules{
@ -40,7 +40,7 @@ func markdownRules() Rules {
{"`[^`]+`", LiteralStringBacktick, nil},
{`[@#][\w/:]+`, NameEntity, nil},
{`(!?\[)([^]]+)(\])(\()([^)]+)(\))`, ByGroups(Text, NameTag, Text, Text, NameAttribute, Text), nil},
{`.|\n`, Other, nil},
{`.|\n`, Text, nil},
},
}
}

@ -2,6 +2,7 @@ package lexers
import (
"regexp"
"slices"
"strings"
"unicode/utf8"
@ -1318,16 +1319,6 @@ func indexAt(str []rune, substr []rune, pos int) int {
return idx
}
// Tells if an array of string contains a string
func contains(s []string, e string) bool {
for _, value := range s {
if value == e {
return true
}
}
return false
}
type rulePosition int
const (
@ -1625,15 +1616,15 @@ func quote(groups []string, state *LexerState) Iterator {
var tokenState string
switch {
case keyword == "qq" || contains(tokenStates, "qq"):
case keyword == "qq" || slices.Contains(tokenStates, "qq"):
tokenState = "qq"
case adverbsStr == "ww" || contains(tokenStates, "ww"):
case adverbsStr == "ww" || slices.Contains(tokenStates, "ww"):
tokenState = "ww"
case contains(tokenStates, "Q-closure") && contains(tokenStates, "Q-variable"):
case slices.Contains(tokenStates, "Q-closure") && slices.Contains(tokenStates, "Q-variable"):
tokenState = "qq"
case contains(tokenStates, "Q-closure"):
case slices.Contains(tokenStates, "Q-closure"):
tokenState = "Q-closure"
case contains(tokenStates, "Q-variable"):
case slices.Contains(tokenStates, "Q-variable"):
tokenState = "Q-variable"
default:
tokenState = "Q"

@ -1,6 +1,7 @@
package chroma
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
@ -135,11 +136,20 @@ func NewLexer(config *Config, rulesFunc func() Rules) (*RegexLexer, error) {
}
// Trace enables debug tracing.
//
// Deprecated: Use SetTracing instead.
func (r *RegexLexer) Trace(trace bool) *RegexLexer {
r.trace = trace
return r
}
// SetTracing enables debug tracing.
//
// This complies with the [TracingLexer] interface.
func (r *RegexLexer) SetTracing(trace bool) {
r.trace = trace
}
// A CompiledRule is a Rule with a pre-compiled regex.
//
// Note that regular expressions are lazily compiled on first use of the lexer.
@ -185,6 +195,7 @@ func (l *LexerState) Get(key interface{}) interface{} {
// Iterator returns the next Token from the lexer.
func (l *LexerState) Iterator() Token { // nolint: gocognit
trace := json.NewEncoder(os.Stderr)
end := len(l.Text)
if l.newlineAdded {
end--
@ -205,14 +216,33 @@ func (l *LexerState) Iterator() Token { // nolint: gocognit
}
l.State = l.Stack[len(l.Stack)-1]
if l.Lexer.trace {
fmt.Fprintf(os.Stderr, "%s: pos=%d, text=%q\n", l.State, l.Pos, string(l.Text[l.Pos:]))
}
selectedRule, ok := l.Rules[l.State]
if !ok {
panic("unknown state " + l.State)
}
var start time.Time
if l.Lexer.trace {
start = time.Now()
}
ruleIndex, rule, groups, namedGroups := matchRules(l.Text, l.Pos, selectedRule)
if l.Lexer.trace {
var length int
if groups != nil {
length = len(groups[0])
} else {
length = -1
}
_ = trace.Encode(Trace{ //nolint
Lexer: l.Lexer.config.Name,
State: l.State,
Rule: ruleIndex,
Pattern: rule.Pattern,
Pos: l.Pos,
Length: length,
Elapsed: float64(time.Since(start)) / float64(time.Millisecond),
})
// fmt.Fprintf(os.Stderr, "%s: pos=%d, text=%q, elapsed=%s\n", l.State, l.Pos, string(l.Text[l.Pos:]), time.Since(start))
}
// No match.
if groups == nil {
// From Pygments :\

@ -65,12 +65,12 @@
<entry type="CommentSingle" style="italic #737994"/>
<entry type="CommentMultiline" style="italic #737994"/>
<entry type="CommentSpecial" style="italic #737994"/>
<entry type="CommentHashbang" style="italic #737994"/>
<entry type="CommentHashbang" style="italic #626880"/>
<entry type="CommentPreproc" style="italic #737994"/>
<entry type="CommentPreprocFile" style="bold #737994"/>
<entry type="Generic" style="#c6d0f5"/>
<entry type="GenericInserted" style="bg:#414559 #a6d189"/>
<entry type="GenericDeleted" style="#e78284 bg:#414559"/>
<entry type="GenericDeleted" style="bg:#414559 #e78284"/>
<entry type="GenericEmph" style="italic #c6d0f5"/>
<entry type="GenericStrong" style="bold #c6d0f5"/>
<entry type="GenericUnderline" style="underline #c6d0f5"/>
@ -80,4 +80,4 @@
<entry type="GenericPrompt" style="#c6d0f5"/>
<entry type="GenericError" style="#e78284"/>
<entry type="GenericTraceback" style="#e78284"/>
</style>
</style>

@ -65,12 +65,12 @@
<entry type="CommentSingle" style="italic #9ca0b0"/>
<entry type="CommentMultiline" style="italic #9ca0b0"/>
<entry type="CommentSpecial" style="italic #9ca0b0"/>
<entry type="CommentHashbang" style="italic #9ca0b0"/>
<entry type="CommentHashbang" style="italic #acb0be"/>
<entry type="CommentPreproc" style="italic #9ca0b0"/>
<entry type="CommentPreprocFile" style="bold #9ca0b0"/>
<entry type="Generic" style="#4c4f69"/>
<entry type="GenericInserted" style="bg:#ccd0da #40a02b"/>
<entry type="GenericDeleted" style="#d20f39 bg:#ccd0da"/>
<entry type="GenericDeleted" style="bg:#ccd0da #d20f39"/>
<entry type="GenericEmph" style="italic #4c4f69"/>
<entry type="GenericStrong" style="bold #4c4f69"/>
<entry type="GenericUnderline" style="underline #4c4f69"/>
@ -80,4 +80,4 @@
<entry type="GenericPrompt" style="#4c4f69"/>
<entry type="GenericError" style="#d20f39"/>
<entry type="GenericTraceback" style="#d20f39"/>
</style>
</style>

@ -65,12 +65,12 @@
<entry type="CommentSingle" style="italic #6e738d"/>
<entry type="CommentMultiline" style="italic #6e738d"/>
<entry type="CommentSpecial" style="italic #6e738d"/>
<entry type="CommentHashbang" style="italic #6e738d"/>
<entry type="CommentHashbang" style="italic #5b6078"/>
<entry type="CommentPreproc" style="italic #6e738d"/>
<entry type="CommentPreprocFile" style="bold #6e738d"/>
<entry type="Generic" style="#cad3f5"/>
<entry type="GenericInserted" style="bg:#363a4f #a6da95"/>
<entry type="GenericDeleted" style="#ed8796 bg:#363a4f"/>
<entry type="GenericDeleted" style="bg:#363a4f #ed8796"/>
<entry type="GenericEmph" style="italic #cad3f5"/>
<entry type="GenericStrong" style="bold #cad3f5"/>
<entry type="GenericUnderline" style="underline #cad3f5"/>
@ -80,4 +80,4 @@
<entry type="GenericPrompt" style="#cad3f5"/>
<entry type="GenericError" style="#ed8796"/>
<entry type="GenericTraceback" style="#ed8796"/>
</style>
</style>

@ -65,12 +65,12 @@
<entry type="CommentSingle" style="italic #6c7086"/>
<entry type="CommentMultiline" style="italic #6c7086"/>
<entry type="CommentSpecial" style="italic #6c7086"/>
<entry type="CommentHashbang" style="italic #6c7086"/>
<entry type="CommentHashbang" style="italic #585b70"/>
<entry type="CommentPreproc" style="italic #6c7086"/>
<entry type="CommentPreprocFile" style="bold #6c7086"/>
<entry type="Generic" style="#cdd6f4"/>
<entry type="GenericInserted" style="bg:#313244 #a6e3a1"/>
<entry type="GenericDeleted" style="#f38ba8 bg:#313244"/>
<entry type="GenericDeleted" style="bg:#313244 #f38ba8"/>
<entry type="GenericEmph" style="italic #cdd6f4"/>
<entry type="GenericStrong" style="bold #cdd6f4"/>
<entry type="GenericUnderline" style="underline #cdd6f4"/>
@ -80,4 +80,4 @@
<entry type="GenericPrompt" style="#cdd6f4"/>
<entry type="GenericError" style="#f38ba8"/>
<entry type="GenericTraceback" style="#f38ba8"/>
</style>
</style>

@ -298,7 +298,7 @@ github.com/NYTimes/gziphandler
## explicit; go 1.15
github.com/Workiva/go-datastructures/rangetree
github.com/Workiva/go-datastructures/slice
# github.com/alecthomas/chroma/v2 v2.19.0
# github.com/alecthomas/chroma/v2 v2.20.0
## explicit; go 1.22
github.com/alecthomas/chroma/v2
github.com/alecthomas/chroma/v2/formatters

Loading…
Cancel
Save