mirror of
https://github.com/go-gitea/gitea
synced 2024-10-20 04:19:50 +02:00
update doc, add tests
This commit is contained in:
parent
d941875c17
commit
fdfd440061
@ -388,6 +388,7 @@ It could add theme meta information into the custom theme CSS file to provide mo
|
|||||||
|
|
||||||
If a custom theme is a dark theme, please set the global css variable `--is-dark-theme: true` in the `:root` block.
|
If a custom theme is a dark theme, please set the global css variable `--is-dark-theme: true` in the `:root` block.
|
||||||
This allows Gitea to adjust the Monaco code editor's theme accordingly.
|
This allows Gitea to adjust the Monaco code editor's theme accordingly.
|
||||||
|
An "auto" theme could be implemented by using "theme-gitea-auto.css" as a reference.
|
||||||
|
|
||||||
```css
|
```css
|
||||||
gitea-theme-meta-info {
|
gitea-theme-meta-info {
|
||||||
|
@ -49,7 +49,11 @@ func parseThemeMetaInfoToMap(cssContent string) map[string]string {
|
|||||||
(
|
(
|
||||||
\s*(--[-\w]+)
|
\s*(--[-\w]+)
|
||||||
\s*:
|
\s*:
|
||||||
\s*("(\\"|[^"])*")
|
\s*(
|
||||||
|
("(\\"|[^"])*")
|
||||||
|
|('(\\'|[^'])*')
|
||||||
|
|([^'";]+)
|
||||||
|
)
|
||||||
\s*;
|
\s*;
|
||||||
\s*
|
\s*
|
||||||
)
|
)
|
||||||
@ -66,9 +70,13 @@ func parseThemeMetaInfoToMap(cssContent string) map[string]string {
|
|||||||
m := map[string]string{}
|
m := map[string]string{}
|
||||||
for _, item := range matchedItems {
|
for _, item := range matchedItems {
|
||||||
v := item[3]
|
v := item[3]
|
||||||
v = strings.TrimPrefix(v, "\"")
|
if strings.HasPrefix(v, `"`) {
|
||||||
v = strings.TrimSuffix(v, "\"")
|
v = strings.TrimSuffix(strings.TrimPrefix(v, `"`), `"`)
|
||||||
v = strings.ReplaceAll(v, `\"`, `"`)
|
v = strings.ReplaceAll(v, `\"`, `"`)
|
||||||
|
} else if strings.HasPrefix(v, `'`) {
|
||||||
|
v = strings.TrimSuffix(strings.TrimPrefix(v, `'`), `'`)
|
||||||
|
v = strings.ReplaceAll(v, `\'`, `'`)
|
||||||
|
}
|
||||||
m[item[2]] = v
|
m[item[2]] = v
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
|
@ -10,6 +10,28 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestParseThemeMetaInfo(t *testing.T) {
|
func TestParseThemeMetaInfo(t *testing.T) {
|
||||||
m := parseThemeMetaInfoToMap(`gitea-theme-meta-info { --k1: "v1"; --k2: "a\"b"; }`)
|
m := parseThemeMetaInfoToMap(`gitea-theme-meta-info {
|
||||||
assert.Equal(t, map[string]string{"--k1": "v1", "--k2": `a"b`}, m)
|
--k1: "v1";
|
||||||
|
--k2: "v\"2";
|
||||||
|
--k3: 'v3';
|
||||||
|
--k4: 'v\'4';
|
||||||
|
--k5: v5;
|
||||||
|
}`)
|
||||||
|
assert.Equal(t, map[string]string{
|
||||||
|
"--k1": "v1",
|
||||||
|
"--k2": `v"2`,
|
||||||
|
"--k3": "v3",
|
||||||
|
"--k4": "v'4",
|
||||||
|
"--k5": "v5",
|
||||||
|
}, m)
|
||||||
|
|
||||||
|
// if an auto theme imports others, the meta info should be extracted from the last one
|
||||||
|
// the meta in imported themes should be ignored to avoid incorrect overriding
|
||||||
|
m = parseThemeMetaInfoToMap(`
|
||||||
|
@media (prefers-color-scheme: dark) { gitea-theme-meta-info { --k1: foo; } }
|
||||||
|
@media (prefers-color-scheme: dark) { gitea-theme-meta-info { --k1: bar; } }
|
||||||
|
gitea-theme-meta-info {
|
||||||
|
--k2: real;
|
||||||
|
}`)
|
||||||
|
assert.Equal(t, map[string]string{"--k2": "real"}, m)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user