forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix broken Chroma CSS styles (go-gitea#23174)
The CSS styles in Gitea themes are out-of-sync of Chroma's styles. This PR introduces a `chroma-style-diff.go` tool to compare the diff. The missing CSS styles have been added manually. They are left as empty to reduce arguments because there was no color for them before. And this PR fixes go-gitea#22348, with just 2 lines changed: `.chroma .kt & .n`, these colors are taken from GitHub. It's good enough for go-gitea#22348 ![image](https://user-images.githubusercontent.com/2114189/221551941-0d27d11d-e71e-498f-8e88-92b558fe4a18.png) --------- Co-authored-by: silverwind <[email protected]>
- Loading branch information
Showing
5 changed files
with
105 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
//go:build ignore | ||
|
||
/* | ||
This tool is used to compare the CSS names in a chroma builtin styles with the Gitea theme CSS names. | ||
It outputs the difference between the two sets of CSS names, eg: | ||
``` | ||
CSS names not in builtin: | ||
.chroma .ln | ||
---- | ||
Builtin CSS names not in file: | ||
.chroma .vm | ||
``` | ||
Developers could use this tool to re-sync the CSS names in the Gitea theme. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"regexp" | ||
"strings" | ||
|
||
"github.com/alecthomas/chroma/v2" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
println("Usage: chroma-style-diff css-or-less-file") | ||
os.Exit(1) | ||
} | ||
|
||
data, err := os.ReadFile(os.Args[1]) | ||
if err != nil { | ||
println(err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
content := string(data) | ||
|
||
// a simple CSS parser to collect CSS names | ||
content = regexp.MustCompile("//.*\r?\n").ReplaceAllString(content, "\n") | ||
content = regexp.MustCompile("/\\*.*?\\*/").ReplaceAllString(content, "") | ||
matches := regexp.MustCompile("\\s*([-.#:\\w\\s]+)\\s*\\{[^}]*}").FindAllStringSubmatch(content, -1) | ||
|
||
cssNames := map[string]bool{} | ||
for _, matchGroup := range matches { | ||
cssName := strings.TrimSpace(matchGroup[1]) | ||
cssNames[cssName] = true | ||
} | ||
|
||
// collect Chroma builtin CSS names | ||
builtin := map[string]bool{} | ||
for tokenType, cssName := range chroma.StandardTypes { | ||
if tokenType > 0 && cssName != "" { | ||
builtin[".chroma ."+cssName] = true | ||
} | ||
} | ||
|
||
// show the diff | ||
println("CSS names not in builtin:") | ||
for cssName := range cssNames { | ||
if !builtin[cssName] { | ||
println(cssName) | ||
} | ||
} | ||
println("----") | ||
println("Builtin CSS names not in file:") | ||
for cssName := range builtin { | ||
if !cssNames[cssName] { | ||
println(cssName) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
@import "../chroma/base.less"; | ||
@import "../chroma/dark.less"; | ||
@import "../codemirror/dark.less"; | ||
|
||
|