From e4a8305b03943baacc3bece0f618802d55b59643 Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 12 Aug 2025 20:26:12 +0200 Subject: [PATCH 1/3] Improve range-diff colors and contrast --- src/gh_range_diff.rs | 53 +++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/src/gh_range_diff.rs b/src/gh_range_diff.rs index 62be6d11..095fa03d 100644 --- a/src/gh_range_diff.rs +++ b/src/gh_range_diff.rs @@ -163,6 +163,26 @@ pub async fn gh_range_diff( body {{ font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace; }} + details {{ + white-space: pre; + }} + summary {{ + font-weight: 800; + }} + .removed-block {{ + background-color: rgb(255, 206, 203); + white-space: pre; + }} + .added-block {{ + background-color: rgb(172, 238, 187); + white-space: pre; + }} + .removed-line {{ + color: #DE0000; + }} + .added-line {{ + color: #2F6500; + }} @media (prefers-color-scheme: dark) {{ body {{ background: #0C0C0C; @@ -171,12 +191,18 @@ pub async fn gh_range_diff( a {{ color: #41a6ff; }} - }} - details {{ - white-space: pre; - }} - summary {{ - font-weight: 800; + .removed-block {{ + background-color: rgba(248, 81, 73, 0.1); + }} + .added-block {{ + background-color: rgba(46, 160, 67, 0.15); + }} + .removed-line {{ + color: #F34848; + }} + .added-line {{ + color: #86D03C; + }} }} @@ -277,18 +303,19 @@ pub async fn gh_range_diff( Ok((StatusCode::OK, headers, html)) } -const REMOVED_BLOCK_SIGN: &str = r#"-"#; -const ADDED_BLOCK_SIGN: &str = r#"+"#; +const REMOVED_BLOCK_SIGN: &str = r#" - "#; +const ADDED_BLOCK_SIGN: &str = r#" + "#; struct HtmlDiffPrinter<'a>(pub &'a Interner<&'a str>); impl HtmlDiffPrinter<'_> { - fn handle_hunk_token(&self, mut f: impl fmt::Write, color: &str, token: &str) -> fmt::Result { + fn handle_hunk_token(&self, mut f: impl fmt::Write, class: &str, token: &str) -> fmt::Result { + write!(f, " ")?; // Highlight the whole the line only if it has changes it-self, otherwise // only highlight the `+`, `-` to avoid distracting users with context // changes. if token.starts_with('+') || token.starts_with('-') { - write!(f, r#""#)?; + write!(f, r#""#)?; pulldown_cmark_escape::escape_html(FmtWriter(&mut f), token)?; write!(f, "")?; } else { @@ -313,7 +340,7 @@ impl UnifiedDiffPrinter for HtmlDiffPrinter<'_> { fn display_context_token(&self, mut f: impl fmt::Write, token: Token) -> fmt::Result { let token = self.0[token]; - write!(f, " ")?; + write!(f, " ")?; pulldown_cmark_escape::escape_html(FmtWriter(&mut f), token)?; if !token.ends_with('\n') { writeln!(f)?; @@ -331,7 +358,7 @@ impl UnifiedDiffPrinter for HtmlDiffPrinter<'_> { for &token in before { let token = self.0[token]; write!(f, "{REMOVED_BLOCK_SIGN}")?; - self.handle_hunk_token(&mut f, "red", token)?; + self.handle_hunk_token(&mut f, "removed-line", token)?; } if !self.0[last].ends_with('\n') { writeln!(f)?; @@ -342,7 +369,7 @@ impl UnifiedDiffPrinter for HtmlDiffPrinter<'_> { for &token in after { let token = self.0[token]; write!(f, "{ADDED_BLOCK_SIGN}")?; - self.handle_hunk_token(&mut f, "green", token)?; + self.handle_hunk_token(&mut f, "added-line", token)?; } if !self.0[last].ends_with('\n') { writeln!(f)?; From d999244fce0731b74c983e3286c8e8f731925681 Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 12 Aug 2025 20:30:13 +0200 Subject: [PATCH 2/3] Improve break-ability of the range-diff title for mobile use-cases --- src/gh_range_diff.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gh_range_diff.rs b/src/gh_range_diff.rs index 095fa03d..80dae578 100644 --- a/src/gh_range_diff.rs +++ b/src/gh_range_diff.rs @@ -207,8 +207,8 @@ pub async fn gh_range_diff( -

range-diff of {oldbase}...{oldhead} {newbase}...{newhead}

-

Bookmarklet: range-diff 🛈 | {ADDED_BLOCK_SIGN} added {REMOVED_BLOCK_SIGN} removed

+

range-diff of {oldbase}...{oldhead} {newbase}...{newhead}

+

Bookmarklet: range-diff 🛈 | {ADDED_BLOCK_SIGN} added {REMOVED_BLOCK_SIGN} removed

"# )?; From 339502616bf193b200c9cc62395d0625a7b832ea Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 12 Aug 2025 20:55:22 +0200 Subject: [PATCH 3/3] Fix scroll and overflow on smaller screen --- src/gh_range_diff.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gh_range_diff.rs b/src/gh_range_diff.rs index 80dae578..41de7901 100644 --- a/src/gh_range_diff.rs +++ b/src/gh_range_diff.rs @@ -168,6 +168,11 @@ pub async fn gh_range_diff( }} summary {{ font-weight: 800; + overflow-wrap: break-word; + white-space: normal; + }} + .diff-content {{ + overflow-x: auto; }} .removed-block {{ background-color: rgb(255, 206, 203); @@ -241,7 +246,7 @@ pub async fn gh_range_diff( writeln!( html, - r#"
{filename} before after
{diff}
"# + r#"
{filename} before after
{diff}
"# )?; } Ok(())