@@ -163,6 +163,26 @@ pub async fn gh_range_diff(
163
163
body {{
164
164
font: 14px SFMono-Regular, Consolas, Liberation Mono, Menlo, monospace;
165
165
}}
166
+ details {{
167
+ white-space: pre;
168
+ }}
169
+ summary {{
170
+ font-weight: 800;
171
+ }}
172
+ .removed-block {{
173
+ background-color: rgb(255, 206, 203);
174
+ white-space: pre;
175
+ }}
176
+ .added-block {{
177
+ background-color: rgb(172, 238, 187);
178
+ white-space: pre;
179
+ }}
180
+ .removed-line {{
181
+ color: #DE0000;
182
+ }}
183
+ .added-line {{
184
+ color: #2F6500;
185
+ }}
166
186
@media (prefers-color-scheme: dark) {{
167
187
body {{
168
188
background: #0C0C0C;
@@ -171,12 +191,18 @@ pub async fn gh_range_diff(
171
191
a {{
172
192
color: #41a6ff;
173
193
}}
174
- }}
175
- details {{
176
- white-space: pre;
177
- }}
178
- summary {{
179
- font-weight: 800;
194
+ .removed-block {{
195
+ background-color: rgba(248, 81, 73, 0.1);
196
+ }}
197
+ .added-block {{
198
+ background-color: rgba(46, 160, 67, 0.15);
199
+ }}
200
+ .removed-line {{
201
+ color: #F34848;
202
+ }}
203
+ .added-line {{
204
+ color: #86D03C;
205
+ }}
180
206
}}
181
207
</style>
182
208
</head>
@@ -277,18 +303,18 @@ pub async fn gh_range_diff(
277
303
Ok ( ( StatusCode :: OK , headers, html) )
278
304
}
279
305
280
- const REMOVED_BLOCK_SIGN : & str = r#"<span style="background-color:red;color:white;">- </span>"# ;
281
- const ADDED_BLOCK_SIGN : & str = r#"<span style="background-color:green;color:white;">+ </span>"# ;
306
+ const REMOVED_BLOCK_SIGN : & str = r#"<span class="removed-block"> - </span>"# ;
307
+ const ADDED_BLOCK_SIGN : & str = r#"<span class="added-block"> + </span>"# ;
282
308
283
309
struct HtmlDiffPrinter < ' a > ( pub & ' a Interner < & ' a str > ) ;
284
310
285
311
impl HtmlDiffPrinter < ' _ > {
286
- fn handle_hunk_token ( & self , mut f : impl fmt:: Write , color : & str , token : & str ) -> fmt:: Result {
312
+ fn handle_hunk_token ( & self , mut f : impl fmt:: Write , class : & str , token : & str ) -> fmt:: Result {
287
313
// Highlight the whole the line only if it has changes it-self, otherwise
288
314
// only highlight the `+`, `-` to avoid distracting users with context
289
315
// changes.
290
316
if token. starts_with ( '+' ) || token. starts_with ( '-' ) {
291
- write ! ( f, r#"<span style="color:{color }">"# ) ?;
317
+ write ! ( f, r#" <span class="{class }">"# ) ?;
292
318
pulldown_cmark_escape:: escape_html ( FmtWriter ( & mut f) , token) ?;
293
319
write ! ( f, "</span>" ) ?;
294
320
} else {
@@ -313,7 +339,7 @@ impl UnifiedDiffPrinter for HtmlDiffPrinter<'_> {
313
339
314
340
fn display_context_token ( & self , mut f : impl fmt:: Write , token : Token ) -> fmt:: Result {
315
341
let token = self . 0 [ token] ;
316
- write ! ( f, " " ) ?;
342
+ write ! ( f, " " ) ?;
317
343
pulldown_cmark_escape:: escape_html ( FmtWriter ( & mut f) , token) ?;
318
344
if !token. ends_with ( '\n' ) {
319
345
writeln ! ( f) ?;
@@ -331,7 +357,7 @@ impl UnifiedDiffPrinter for HtmlDiffPrinter<'_> {
331
357
for & token in before {
332
358
let token = self . 0 [ token] ;
333
359
write ! ( f, "{REMOVED_BLOCK_SIGN}" ) ?;
334
- self . handle_hunk_token ( & mut f, "red " , token) ?;
360
+ self . handle_hunk_token ( & mut f, "removed-line " , token) ?;
335
361
}
336
362
if !self . 0 [ last] . ends_with ( '\n' ) {
337
363
writeln ! ( f) ?;
@@ -342,7 +368,7 @@ impl UnifiedDiffPrinter for HtmlDiffPrinter<'_> {
342
368
for & token in after {
343
369
let token = self . 0 [ token] ;
344
370
write ! ( f, "{ADDED_BLOCK_SIGN}" ) ?;
345
- self . handle_hunk_token ( & mut f, "green " , token) ?;
371
+ self . handle_hunk_token ( & mut f, "added-line " , token) ?;
346
372
}
347
373
if !self . 0 [ last] . ends_with ( '\n' ) {
348
374
writeln ! ( f) ?;
0 commit comments