From e670985f6d50132531ad3025ada39a1c2c9520dc Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Sun, 17 Jan 2021 19:27:59 +0000 Subject: Use
 and  to print diffs

This correctly preserves whitespace in browsers without CSS, as an
alternative to [1].

[1]: https://80x24.org/cgit.git/commit/?id=7c692e6137697de8a8473c4de5c3de4fb03a2989
---
 www/git.causal.agency/cgit/cgit.css  | 14 ++++----------
 www/git.causal.agency/cgit/ui-diff.c | 30 +++++++++++++++++-------------
 2 files changed, 21 insertions(+), 23 deletions(-)

diff --git a/www/git.causal.agency/cgit/cgit.css b/www/git.causal.agency/cgit/cgit.css
index dac791b6..36826b07 100644
--- a/www/git.causal.agency/cgit/cgit.css
+++ b/www/git.causal.agency/cgit/cgit.css
@@ -533,26 +533,20 @@ div#cgit table.diff {
 	width: 100%;
 }
 
-div#cgit table.diff td {
-	font-family: monospace;
-	white-space: pre;
-}
-
-div#cgit table.diff td div.head {
+div#cgit table.diff td span.head {
 	font-weight: bold;
-	margin-top: 1em;
 	color: black;
 }
 
-div#cgit table.diff td div.hunk {
+div#cgit table.diff td span.hunk {
 	color: #009;
 }
 
-div#cgit table.diff td div.add {
+div#cgit table.diff td span.add {
 	color: green;
 }
 
-div#cgit table.diff td div.del {
+div#cgit table.diff td span.del {
 	color: red;
 }
 
diff --git a/www/git.causal.agency/cgit/ui-diff.c b/www/git.causal.agency/cgit/ui-diff.c
index 329c3506..97c1ca02 100644
--- a/www/git.causal.agency/cgit/ui-diff.c
+++ b/www/git.causal.agency/cgit/ui-diff.c
@@ -231,11 +231,11 @@ static void print_line(char *line, int len)
 	else if (line[0] == '@')
 		class = "hunk";
 
-	htmlf("
", class); + htmlf("", class); line[len-1] = '\0'; html_txt(line); - html("
"); line[len-1] = c; + html("
\n"); } static void header(const struct object_id *oid1, char *path1, int mode1, @@ -245,22 +245,23 @@ static void header(const struct object_id *oid1, char *path1, int mode1, int subproject; subproject = (S_ISGITLINK(mode1) || S_ISGITLINK(mode2)); - html("
"); + html(""); html("diff --git a/"); html_txt(path1); html(" b/"); html_txt(path2); + html("\n"); if (mode1 == 0) - htmlf("
new file mode %.6o", mode2); + htmlf("new file mode %.6o\n", mode2); if (mode2 == 0) - htmlf("
deleted file mode %.6o", mode1); + htmlf("deleted file mode %.6o\n", mode1); if (!subproject) { abbrev1 = xstrdup(find_unique_abbrev(oid1, DEFAULT_ABBREV)); abbrev2 = xstrdup(find_unique_abbrev(oid2, DEFAULT_ABBREV)); - htmlf("
index %s..%s", abbrev1, abbrev2); + htmlf("index %s..%s", abbrev1, abbrev2); free(abbrev1); free(abbrev2); if (mode1 != 0 && mode2 != 0) { @@ -268,28 +269,31 @@ static void header(const struct object_id *oid1, char *path1, int mode1, if (mode2 != mode1) htmlf("..%.6o", mode2); } + html("\n"); if (is_null_oid(oid1)) { path1 = "dev/null"; - html("
--- /"); + html("--- /"); } else - html("
--- a/"); + html("--- a/"); if (mode1 != 0) cgit_tree_link(path1, NULL, NULL, ctx.qry.head, oid_to_hex(old_rev_oid), path1); else html_txt(path1); + html("\n"); if (is_null_oid(oid2)) { path2 = "dev/null"; - html("
+++ /"); + html("+++ /"); } else - html("
+++ b/"); + html("+++ b/"); if (mode2 != 0) cgit_tree_link(path2, NULL, NULL, ctx.qry.head, oid_to_hex(new_rev_oid), path2); else html_txt(path2); + html("\n"); } - html("
"); + html(""); } static void filepair_cb(struct diff_filepair *pair) @@ -488,12 +492,12 @@ void cgit_print_diff(const char *new_rev, const char *old_rev, html(""); } else { html("
"); - html(""); + html(""); html("
"); + html("
");
 	}
 	cgit_diff_tree(old_rev_oid, new_rev_oid, filepair_cb, prefix,
 		       ctx.qry.ignorews);
 	if (!use_ssdiff)
-		html("
"); if (show_ctrls) -- cgit 1.4.1 link back to cgit home pageJason A. Donenfeld 2014-12-23ui-shared: show absolute time in tooltip for relative datesJohn Keeping 2014-12-23git: use xz compressed archive for downloadChristian Hesse 2014-12-23match other common markdown file extensionsChris Burroughs 2014-12-23repolist: add owner-filterChris Burroughs 2014-12-23ui-shared: add rel-vcs microformat links to HTML headerJohn Keeping 2014-12-23ui-summary: add "rel='vcs-git'" to clone URL linksJohn Keeping 2014-12-23Extract clone URL printing to ui-shared.cJohn Keeping 2014-12-23Remove trailing slash after remove-suffixLukas Fleischer 2014-12-23git: update to v2.2.1Christian Hesse 2014-12-13filter: fix libravatar email-filter https issueChristian Hesse 2014-12-13ui-diff: add "stat only" diff typeJohn Keeping 2014-12-13Change "ss" diff flag to an enumJohn Keeping 2014-12-13ui-shared: remove toggle_ssdiff arg to cgit_diff_link()John Keeping 2014-12-13ui-shared: remove toggle_ssdiff arg to cgit_commit_link()John Keeping 2014-08-07git: update to v2.0.4John Keeping 2014-08-07Always check if README exists in choose_readme()Lukas Fleischer 2014-08-01cgitrc.5: we mean a cgi response, not requestJason A. Donenfeld 2014-07-28ui-stats.c: set parent pointer to NULL after freeing itJohn Keeping 2014-07-28git: update to v2.0.3John Keeping 2014-07-28parsing.c: make commit buffer constJohn Keeping 2014-06-30Bump version.Jason A. Donenfeld 2014-06-29remove debug fprinf() calls that sneaked in with commit 79c985Christian Hesse 2014-06-28git: update to 2.0.1Christian Hesse 2014-06-28ui-patch: Flush stdout after outputting dataJohn Keeping 2014-06-28ui-log: ignore unhandled argumentsJohn Keeping 2014-06-28git: update for git 2.0Christian Hesse 2014-04-17remove trailing whitespaces from source filesChristian Hesse 2014-04-12git: update to 1.9.2Christian Hesse 2014-04-05Fix cgit_parse_url when a repo url is contained in another repo urlJulian Maurice 2014-03-20Makefile: use more reliable git tarball mirrorJason A. Donenfeld 2014-03-20git: update to 1.9.1Christian Hesse