From ada6a68b4f25c912705542a6b03aae7ffffb5e99 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Sat, 5 Oct 2024 16:47:32 +0200 Subject: feat: Make syntax highlight configurable Now cerrado has configurable theme through "syntax-highlight". --- pkg/handler/git/handler.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'pkg/handler') diff --git a/pkg/handler/git/handler.go b/pkg/handler/git/handler.go index 6fae146..5739c8e 100644 --- a/pkg/handler/git/handler.go +++ b/pkg/handler/git/handler.go @@ -27,18 +27,19 @@ import ( type ( GitHandler struct { gitService *service.GitService - readmePath string + config configurationRepository } configurationRepository interface { GetRootReadme() string + GetSyntaxHighlight() string } ) func NewGitHandler(gitService *service.GitService, confRepo configurationRepository) *GitHandler { return &GitHandler{ gitService: gitService, - readmePath: confRepo.GetRootReadme(), + config: confRepo, } } @@ -48,7 +49,7 @@ func (g *GitHandler) List(w http.ResponseWriter, _ *http.Request) error { return err } - f, err := os.Open(g.readmePath) + f, err := os.Open(g.config.GetRootReadme()) if err != nil { return err } @@ -280,7 +281,8 @@ func (g *GitHandler) Blob(w http.ResponseWriter, r *http.Request) error { filename := filepath.Base(rest) lexer := GetLexers(filename) - style := styles.Get("xcode") + style := styles.Get(g.config.GetSyntaxHighlight()) + formatter := html.New( html.WithLineNumbers(true), html.WithLinkableLineNumbers(true, "L"), -- cgit v1.2.3