cerrado @ 3be25766027178489a0c5f1f82e65f9be518c79c

feat: Add chroma support
diff --git a/go.mod b/go.mod
index b8b36b4cc85febdf92f178dea6604511c034b56d..ff4f2dd03286fea07e936a6b3961402b2971dae9 100644
--- a/go.mod
+++ b/go.mod
@@ -4,9 +4,13 @@ go 1.22.2
 
 require (
 	git.sr.ht/~emersion/go-scfg v0.0.0-20240128091534-2ae16e782082
+	github.com/alecthomas/chroma/v2 v2.13.0
 	github.com/google/go-cmp v0.6.0
 	github.com/valyala/quicktemplate v1.7.0
 	golang.org/x/sync v0.7.0
 )
 
-require github.com/valyala/bytebufferpool v1.0.0 // indirect
+require (
+	github.com/dlclark/regexp2 v1.11.0 // indirect
+	github.com/valyala/bytebufferpool v1.0.0 // indirect
+)
diff --git a/go.sum b/go.sum
index 0ba6fdb880c9cf8d7bef209163294c73990aab69..15e574af4ac10ebbfb80200b39121f4d3cda7584 100644
--- a/go.sum
+++ b/go.sum
@@ -1,12 +1,22 @@
 git.sr.ht/~emersion/go-scfg v0.0.0-20240128091534-2ae16e782082 h1:9Udx5fm4vRtmgDIBjy2ef5QioHbzpw5oHabbhpAUyEw=
 git.sr.ht/~emersion/go-scfg v0.0.0-20240128091534-2ae16e782082/go.mod h1:ybgvEJTIx5XbaspSviB3KNa6OdPmAZqDoSud7z8fFlw=
+github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
+github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
+github.com/alecthomas/chroma/v2 v2.13.0 h1:VP72+99Fb2zEcYM0MeaWJmV+xQvz5v5cxRHd+ooU1lI=
+github.com/alecthomas/chroma/v2 v2.13.0/go.mod h1:BUGjjsD+ndS6eX37YgTchSEG+Jg9Jv1GiZs9sqPqztk=
+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/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y=
 github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxKI=
+github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
 github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
 github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
+github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
+github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
 github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg=
 github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
 github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
diff --git a/main.go b/main.go
index 55f866e18d0497c7d8c44ff21ea0adf1517b90be..3d6411d1c2cac54353b520600f1ffe6fa21054b3 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,7 @@
 package main
 
 import (
+	"bytes"
 	"context"
 	"encoding/json"
 	"flag"
@@ -10,6 +11,10 @@ 	"os"
 	"os/signal"
 	"time"
 
+	"github.com/alecthomas/chroma/v2/formatters/html"
+	"github.com/alecthomas/chroma/v2/lexers"
+	"github.com/alecthomas/chroma/v2/styles"
+
 	"git.gabrielgio.me/cerrado/pkg/config"
 	"git.gabrielgio.me/cerrado/pkg/worker"
 	"git.gabrielgio.me/cerrado/templates"
@@ -33,6 +38,7 @@ 	flag.Parse()
 
 	mux := http.NewServeMux()
 	mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
+		slog.Info("Handling index")
 
 		f, err := os.Open(*configPath)
 		if err != nil {
@@ -52,8 +58,26 @@ 			slog.Error("Error parsing json", "error", err)
 			return
 		}
 
+		lexer := lexers.Get("json")
+		style := styles.Get("monokailight")
+		formatter := html.New(
+			html.WithLineNumbers(true),
+		)
+		iterator, err := lexer.Tokenise(nil, string(b))
+		if err != nil {
+			slog.Error("Error tokenise", "error", err)
+			return
+		}
+
+		var code bytes.Buffer
+		err = formatter.Format(&code, style, iterator)
+		if err != nil {
+			slog.Error("Error format", "error", err)
+			return
+		}
+
 		hello := &templates.HelloPage{
-			Body: string(b),
+			Body: code.String(),
 		}
 
 		templates.WritePageTemplate(w, hello)
diff --git a/templates/helloworld.qtpl b/templates/helloworld.qtpl
index 02c09681378f5fad6de6fa1ec9550d59233cf887..66287eac78fadb51d34da5420d2700ff4b4bb511 100644
--- a/templates/helloworld.qtpl
+++ b/templates/helloworld.qtpl
@@ -9,7 +9,7 @@
 {% func (p *HelloPage) Content() %}
 HelloWorld
 
-{%s p.Body %}
+{%s= p.Body %}
 {% endfunc %}
 
 {% func (p *HelloPage) Script() %}
diff --git a/templates/helloworld.qtpl.go b/templates/helloworld.qtpl.go
index 9ef78f55e201f7d50d7d373dc40fa30c682169bf..a12455fe6c09e8027a97fd8b4a1fe30179553928 100644
--- a/templates/helloworld.qtpl.go
+++ b/templates/helloworld.qtpl.go
@@ -63,7 +63,7 @@ HelloWorld
 
 `)
 //line helloworld.qtpl:12
-	qw422016.E().S(p.Body)
+	qw422016.N().S(p.Body)
 //line helloworld.qtpl:12
 	qw422016.N().S(`
 `)