From fb386ab10728de4c11581bae942312fdd954dfd5 Mon Sep 17 00:00:00 2001
From: Anirudh Oppiliappan
Date: Thu, 27 Mar 2025 13:49:06 +0200
Subject: [PATCH] appview: blob: fix weird bg color issue
---
appview/pages/chroma.go | 40 ++++++++++++++++++++++++++
appview/pages/pages.go | 3 +-
appview/pages/templates/repo/blob.html | 13 +--------
tailwind.config.js | 2 +-
4 files changed, 43 insertions(+), 15 deletions(-)
create mode 100644 appview/pages/chroma.go
diff --git a/appview/pages/chroma.go b/appview/pages/chroma.go
new file mode 100644
index 00000000..a43e34ce
--- /dev/null
+++ b/appview/pages/chroma.go
@@ -0,0 +1,40 @@
+package pages
+
+import "github.com/alecthomas/chroma/v2"
+
+var tangledTheme map[chroma.TokenType]string = map[chroma.TokenType]string{
+ // Keywords
+ chroma.Keyword: "text-blue-400",
+ chroma.KeywordConstant: "text-indigo-400",
+ chroma.KeywordDeclaration: "text-purple-400",
+ chroma.KeywordNamespace: "text-teal-400",
+ chroma.KeywordReserved: "text-pink-400",
+
+ // Names
+ chroma.Name: "text-gray-700",
+ chroma.NameFunction: "text-green-500",
+ chroma.NameClass: "text-orange-400",
+ chroma.NameNamespace: "text-cyan-500",
+ chroma.NameVariable: "text-red-400",
+ chroma.NameBuiltin: "text-yellow-500",
+
+ // Literals
+ chroma.LiteralString: "text-emerald-500 ",
+ chroma.LiteralStringChar: "text-lime-500",
+ chroma.LiteralNumber: "text-rose-400",
+ chroma.LiteralNumberFloat: "text-amber-500",
+
+ // Operators
+ chroma.Operator: "text-blue-500",
+ chroma.OperatorWord: "text-indigo-500",
+
+ // Comments
+ chroma.Comment: "text-gray-500 italic",
+ chroma.CommentSingle: "text-gray-400 italic",
+
+ // Generic
+ chroma.GenericError: "text-red-600",
+ chroma.GenericHeading: "text-purple-500 font-bold",
+ chroma.GenericDeleted: "text-red-400 line-through",
+ chroma.GenericInserted: "text-green-400 underline",
+}
diff --git a/appview/pages/pages.go b/appview/pages/pages.go
index dd5a91b5..17b95322 100644
--- a/appview/pages/pages.go
+++ b/appview/pages/pages.go
@@ -431,13 +431,12 @@ func (p *Pages) RepoBlob(w io.Writer, params RepoBlobParams) error {
style := styles.Get("bw")
b := style.Builder()
b.Add(chroma.LiteralString, "noitalic")
- b.Add(chroma.Background, "bg:")
style, _ = b.Build()
if params.Lines < 5000 {
c := params.Contents
formatter := chromahtml.New(
- chromahtml.InlineCode(true),
+ chromahtml.InlineCode(false),
chromahtml.WithLineNumbers(true),
chromahtml.WithLinkableLineNumbers(true, "L"),
chromahtml.Standalone(false),
diff --git a/appview/pages/templates/repo/blob.html b/appview/pages/templates/repo/blob.html
index bf1b648c..071c9052 100644
--- a/appview/pages/templates/repo/blob.html
+++ b/appview/pages/templates/repo/blob.html
@@ -52,18 +52,7 @@
{{ else }}
- {{ range $idx, $line := $lines }}
- {{ $linenr := add $idx 1 }}
-
- {{ end }}
+
{{ $.Contents | escapeHtml }}
{{ end }}
{{ end }}
diff --git a/tailwind.config.js b/tailwind.config.js
index 465cc5de..93eae04d 100644
--- a/tailwind.config.js
+++ b/tailwind.config.js
@@ -2,7 +2,7 @@
const colors = require("tailwindcss/colors");
module.exports = {
- content: ["./appview/pages/templates/**/*.html"],
+ content: ["./appview/pages/templates/**/*.html", "./appview/pages/chroma.go"],
darkMode: "media",
theme: {
container: {
--
2.51.2