1
0
mirror of https://github.com/alecthomas/chroma.git synced 2025-02-15 13:33:12 +02:00

89 Commits

Author SHA1 Message Date
Alec Thomas
40542a6255 refactor: migrate a bunch more Go-based lexers to XML
Also rename some existing XML lexers to their canonical XML name.
2023-09-09 12:29:23 +10:00
Alec Thomas
4dd2cbef84 fix: bump to latest dclark/regexp2
Fixes #805
2023-09-09 11:46:52 +10:00
Toshimaru
9864526122
deps: update go modules (#810) 2023-08-13 10:46:59 +10:00
Alec Thomas
7e30655df1 Allow custom XML lexers and styles to be loaded from the command-line. 2023-03-17 10:21:26 +11:00
JakobDev
31310888c4
Fix Playground on Windows (#758) 2023-03-03 04:52:55 -08:00
toshimaru
db073d869d deps: Bump modules for cmd/chromad
- alecthomas/kong
- alecthomas/kong-hcl
- gorilla/csrf
- gorilla/handlers
- gorilla/mux
2023-01-16 01:47:17 +11:00
toshimaru
4553686e33 deps: Bump go modules for cmd/chroma
- alecthomas/kong
- mattn/go-colorable
- mattn/go-isatty
2023-01-16 01:47:17 +11:00
Alec Thomas
d330b760dc feat: support sharing in playground 2023-01-11 16:37:03 -05:00
Alec Thomas
b2643973d2 fix: ensure HTML flags apply to --html-styles
Fixes #639
2022-11-01 19:08:21 +11:00
Alec Thomas
d0e811c0ef
fix: use a class with line links when requested (#692)
Fixes #683
2022-10-31 23:28:30 -07:00
Alec Thomas
40b7a9135a Upgrade project to Go 1.19 and switch to alecthomas/assert/v2 2022-10-18 08:55:38 +11:00
Jon Eskin
d38b87110b Add linkable line number option to CLI 2022-10-03 10:17:42 +11:00
Alec Thomas
4dfc2caf03 refactor: run go mod tidy on chromad 2022-05-29 00:39:33 +10:00
Alec Thomas
bd0ae5073a fix: upgrade goreleaser
Hopefully (works locally) fix #611.
2022-03-02 06:21:58 +11:00
Alec Thomas
59896e357d Flag groups for "chroma", making it a bit clearer for users. 2022-01-27 22:54:59 +11:00
Alec Thomas
cc2dd5b8ad Version 2 of Chroma
This cleans up the API in general, removing a bunch of deprecated stuff,
cleaning up circular imports, etc.

But the biggest change is switching to an optional XML format for the
regex lexer.

Having lexers defined only in Go is not ideal for a couple of reasons.
Firstly, it impedes a significant portion of contributors who use Chroma
in Hugo, but don't know Go. Secondly, it bloats the binary size of any
project that imports Chroma.

Why XML? YAML is an abomination and JSON is not human editable. XML
also compresses very well (eg. Go template lexer XML compresses from
3239 bytes to 718).

Why a new syntax format? All major existing formats rely on the
Oniguruma regex engine, which is extremely complex and for which there
is no Go port.

Why not earlier? Prior to the existence of fs.FS this was not a viable
option.

Benchmarks:

    $ hyperfine --warmup 3 \
        './chroma.master --version' \
        './chroma.xml-pre-opt --version' \
        './chroma.xml --version'
    Benchmark 1: ./chroma.master --version
      Time (mean ± σ):       5.3 ms ±   0.5 ms    [User: 3.6 ms, System: 1.4 ms]
      Range (min … max):     4.2 ms …   6.6 ms    233 runs

    Benchmark 2: ./chroma.xml-pre-opt --version
      Time (mean ± σ):      50.6 ms ±   0.5 ms    [User: 52.4 ms, System: 3.6 ms]
      Range (min … max):    49.2 ms …  51.5 ms    51 runs

    Benchmark 3: ./chroma.xml --version
      Time (mean ± σ):       6.9 ms ±   1.1 ms    [User: 5.1 ms, System: 1.5 ms]
      Range (min … max):     5.7 ms …  19.9 ms    196 runs

    Summary
      './chroma.master --version' ran
        1.30 ± 0.23 times faster than './chroma.xml --version'
        9.56 ± 0.83 times faster than './chroma.xml-pre-opt --version'

A slight increase in init time, but I think this is okay given the
increase in flexibility.

And binary size difference:

    $ du -h lexers.test*
    $ du -sh chroma*                                                                                                                                                                                                                                                                                                                                                                                                                                                             951371ms
    8.8M	chroma.master
    7.8M	chroma.xml
    7.8M	chroma.xml-pre-opt

Benchmarks:

    $ hyperfine --warmup 3 \
        './chroma.master --version' \
        './chroma.xml-pre-opt --version' \
        './chroma.xml --version'
    Benchmark 1: ./chroma.master --version
      Time (mean ± σ):       5.3 ms ±   0.5 ms    [User: 3.6 ms, System: 1.4 ms]
      Range (min … max):     4.2 ms …   6.6 ms    233 runs

    Benchmark 2: ./chroma.xml-pre-opt --version
      Time (mean ± σ):      50.6 ms ±   0.5 ms    [User: 52.4 ms, System: 3.6 ms]
      Range (min … max):    49.2 ms …  51.5 ms    51 runs

    Benchmark 3: ./chroma.xml --version
      Time (mean ± σ):       6.9 ms ±   1.1 ms    [User: 5.1 ms, System: 1.5 ms]
      Range (min … max):     5.7 ms …  19.9 ms    196 runs

    Summary
      './chroma.master --version' ran
        1.30 ± 0.23 times faster than './chroma.xml --version'
        9.56 ± 0.83 times faster than './chroma.xml-pre-opt --version'

Incompatible changes:

- (*RegexLexer).SetAnalyser: changed from func(func(text string) float32) *RegexLexer to func(func(text string) float32) Lexer
- (*TokenType).UnmarshalJSON: removed
- Lexer.AnalyseText: added
- Lexer.SetAnalyser: added
- Lexer.SetRegistry: added
- MustNewLazyLexer: removed
- MustNewLexer: changed from func(*Config, Rules) *RegexLexer to func(*Config, func() Rules) *RegexLexer
- Mutators: changed from func(...Mutator) MutatorFunc to func(...Mutator) Mutator
- NewLazyLexer: removed
- NewLexer: changed from func(*Config, Rules) (*RegexLexer, error) to func(*Config, func() Rules) (*RegexLexer, error)
- Pop: changed from func(int) MutatorFunc to func(int) Mutator
- Push: changed from func(...string) MutatorFunc to func(...string) Mutator
- TokenType.MarshalJSON: removed
- Using: changed from func(Lexer) Emitter to func(string) Emitter
- UsingByGroup: changed from func(func(string) Lexer, int, int, ...Emitter) Emitter to func(int, int, ...Emitter) Emitter
2022-01-27 15:22:00 +11:00
Alec Thomas
0e8972ef9b Fix chromad build. 2021-10-17 09:07:08 +11:00
toshimaru
368394959b Update go modules
- mattn/go-colorable
- mattn/go-isatty
- stretchr/testify
2021-09-27 09:43:14 +10:00
Alec Thomas
54fd3bc12f Clean up imports and make cmd/chroma its own module. 2021-06-18 16:56:50 +10:00
Alec Thomas
35539cf059 gofmt 2021-05-11 13:06:37 +10:00
Ville Skyttä
465a27c08a
cmd: --fail earlier without reading entire input files (#502) 2021-05-11 11:03:16 +10:00
Ville Skyttä
e87e5b2208 cmd: add optional silent fail mode on no specific lexer
Makes use of chroma easier in/as less(1) preprocessors.

https://manpages.debian.org/less#INPUT_PREPROCESSOR
  export LESSOPEN='| p() { chroma --fail "$1" || cat "$1"; }; p "%s"'

https://manpages.debian.org/lesspipe#USER_DEFINED_FILTERS
  ln -s ~/go/bin/chroma ~/.lessfilter
2021-05-09 08:46:49 +10:00
Alec Thomas
c44c690de2 Switch chromad to go:embed and show version. 2021-04-25 08:25:51 +10:00
Alec Thomas
7410d4a2dc Update chromad modules. 2021-04-25 08:07:12 +10:00
Alec Thomas
cc53faa932 Add option to preserve all HTML classes.
Fixes #346.
2020-04-13 07:36:37 +10:00
Alec Thomas
bac74c1016 Fix Makefile. 2020-01-02 21:50:01 +11:00
Alec Thomas
9fb54c5f75 Add separate go module for ./cmd/chromad.
Fixes #261.
2019-11-28 11:40:24 +11:00
Alec Thomas
2d34ebacdb Simplify configuration of HTML call. 2019-11-28 11:21:12 +11:00
Bjørn Erik Pedersen
5921c52787 Add bool argument to WithClasses, WithLineNumbers etc.
This allows the boolean options to be reconfigured, e.g:

```go
options := getOptions()
options = append(options, html.WithLineNumbers(true))
```

Fixes #301
2019-11-22 10:13:00 +11:00
Alec Thomas
73d11b3c45 Clear background colour for TTY formatters. 2019-10-15 21:08:17 +11:00
rsteube
22511fb8e4 added svg formatter
basic version without any options. colors and font-styles seem to be ok.
rough support for text background in styles like `murphy` using predrawn
rectangles (svg has no text background attribute).

things to improve:
- svg width attribute (`<svg width=""`)
- linenumbers
- highlighting
- embedded font
- tabwidth option
- margins?
- better position/width calculation (rectangles not correctly drawn on
resize)
2019-09-30 09:43:27 +10:00
Alec Thomas
bbbfbe4e7a Update to more recent golangci-lint. 2019-07-19 18:57:05 +10:00
Alec Thomas
2ec7e6c2d1 Use Kong enum for lexers, formatters and styles. 2019-07-19 16:29:13 +10:00
Alec Thomas
3411213e25 Temporarily use go.rice fork with correct asset timestamping/versioning. 2019-07-17 11:24:40 +10:00
Alec Thomas
9fbb21283d Render full HTML. 2019-07-16 23:24:37 +10:00
Alec Thomas
89e7ddc5d9 Disable spellchecking/autocomplete. 2019-07-16 22:22:30 +10:00
Alec Thomas
5da2819c7d Add cache-busting version. 2019-07-16 22:19:43 +10:00
Alec Thomas
c86a26959c Add info block. 2019-07-16 22:08:09 +10:00
Alec Thomas
aa71d61cc0 Only allow POST to /api/render. 2019-07-16 21:47:36 +10:00
Alec Thomas
ffa8a4f67f CORS support + raw HTML view + more. 2019-07-16 21:31:37 +10:00
Alec Thomas
bdb587cd37 Make playground completely dynamic. 2019-07-16 18:45:54 +10:00
Alec Thomas
2332264124 Add CSRF support to chromad. 2019-07-16 16:17:37 +10:00
Alec Thomas
7a7fde259b Split out chromad resources. 2019-07-16 15:45:06 +10:00
Alec Thomas
91b44ffd76 Lint isses. 2019-07-16 14:26:56 +10:00
Alec Thomas
10cee2ee79 Add Chroma playground.
Found here: https://swapoff.org/chroma/playground
2019-07-16 14:19:54 +10:00
Alec Thomas
da5ac60d8c Add golangci-lint and fix all lint issues. 2018-12-31 22:46:59 +11:00
Alec Thomas
3b3f74c6a5 Fix stdin mode in chroma tool.
Fixes #207.
2018-12-14 10:42:19 +11:00
Alec Thomas
3175fa52d7 Support go modules + VB.Net lexer.
Fixes #201.
2018-12-03 20:38:33 -10:00
Daniel Eloff
9c3abeae1d Tokens by value (#187)
This results in about a 8% improvement in speed.
2018-11-04 10:22:51 +11:00
Felix Knischewski
e36baa268a Add option to prevent surroundign pre tags 2018-09-18 19:44:44 +10:00