diff options
author | Runxi Yu <me@runxiyu.org> | 2025-02-14 13:31:17 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-02-14 13:53:34 +0800 |
commit | b072d8bc48e35dc814642ae0cee190db42fb56cf (patch) | |
tree | 5dc381baa29814072bc545765cbe73a293270ecc | |
parent | *: Make the forge title configurable (diff) | |
download | forge-b072d8bc48e35dc814642ae0cee190db42fb56cf.tar.gz forge-b072d8bc48e35dc814642ae0cee190db42fb56cf.tar.zst forge-b072d8bc48e35dc814642ae0cee190db42fb56cf.zip |
reop_commit: Fix immediate newlines after <pre>
-rw-r--r-- | http_handle_repo_commit.go | 20 | ||||
-rw-r--r-- | static/style.css | 8 | ||||
-rw-r--r-- | templates/repo_commit.html.tmpl | 6 |
3 files changed, 25 insertions, 9 deletions
diff --git a/http_handle_repo_commit.go b/http_handle_repo_commit.go index d4956d1..8e5cdbf 100644 --- a/http_handle_repo_commit.go +++ b/http_handle_repo_commit.go @@ -14,7 +14,12 @@ import ( type usable_file_patch struct { From diff.File To diff.File - Chunks []diff.Chunk + Chunks []usable_chunk +} + +type usable_chunk struct { + Operation diff.Operation + Content string } func handle_repo_commit(w http.ResponseWriter, r *http.Request, params map[string]any) { @@ -70,8 +75,19 @@ func handle_repo_commit(w http.ResponseWriter, r *http.Request, params map[strin if to == nil { to = fake_diff_file_null } + chunks := []usable_chunk{} + for _, chunk := range file_patch.Chunks() { + content := chunk.Content() + if len(content) > 0 && content[0] == '\n' { + content = "\n" + content + } // Horrible hack to fix how browsers newlines that immediately proceed <pre> + chunks = append(chunks, usable_chunk{ + Operation: chunk.Type(), + Content: content, + }) + } usable_file_patch := usable_file_patch{ - Chunks: file_patch.Chunks(), + Chunks: chunks, From: from, To: to, } diff --git a/static/style.css b/static/style.css index fae12c9..8441a0c 100644 --- a/static/style.css +++ b/static/style.css @@ -147,18 +147,18 @@ td#readme > *:first-child { color: grey; } .chunk-addition { - color: green; + background-color: green; } @media (prefers-color-scheme: dark) { .chunk-addition { - color: lime; + background-color: lime; } } .chunk-deletion { - color: red; + background-color: red; } .chunk-unknown { - color: yellow; + background-color: yellow; } pre.chunk { margin-top: 0; diff --git a/templates/repo_commit.html.tmpl b/templates/repo_commit.html.tmpl index 658ed57..d07845b 100644 --- a/templates/repo_commit.html.tmpl +++ b/templates/repo_commit.html.tmpl @@ -69,11 +69,11 @@ </label> <div class="file-content toggle-on-content scroll"> {{ range .Chunks }} - {{ if eq .Type 0 }} + {{ if eq .Operation 0 }} <pre class="chunk chunk-unchanged">{{ .Content }}</pre> - {{ else if eq .Type 1 }} + {{ else if eq .Operation 1 }} <pre class="chunk chunk-addition">{{ .Content }}</pre> - {{ else if eq .Type 2 }} + {{ else if eq .Operation 2 }} <pre class="chunk chunk-deletion">{{ .Content }}</pre> {{ else }} <pre class="chunk chunk-unknown">{{ .Content }}</pre> |