@@ -271,6 +271,28 @@ pub async fn gh_range_diff(
271
271
272
272
struct HtmlDiffPrinter < ' a > ( pub & ' a Interner < & ' a str > ) ;
273
273
274
+ impl HtmlDiffPrinter < ' _ > {
275
+ fn handle_hunk_token (
276
+ & self ,
277
+ mut f : impl fmt:: Write ,
278
+ span_open : & str ,
279
+ token : & str ,
280
+ ) -> fmt:: Result {
281
+ write ! ( f, "{span_open}" ) ?;
282
+ // Highlight the whole the line only if it has changes it-self, otherwise
283
+ // only highlight the `+`, `-` to avoid distracting users with context
284
+ // changes.
285
+ if token. starts_with ( '+' ) || token. starts_with ( '-' ) {
286
+ pulldown_cmark_escape:: escape_html ( FmtWriter ( & mut f) , token) ?;
287
+ write ! ( f, "</span>" ) ?;
288
+ } else {
289
+ write ! ( f, "</span>" ) ?;
290
+ pulldown_cmark_escape:: escape_html ( FmtWriter ( & mut f) , token) ?;
291
+ }
292
+ Ok ( ( ) )
293
+ }
294
+ }
295
+
274
296
impl UnifiedDiffPrinter for HtmlDiffPrinter < ' _ > {
275
297
fn display_header (
276
298
& self ,
@@ -303,9 +325,7 @@ impl UnifiedDiffPrinter for HtmlDiffPrinter<'_> {
303
325
if let Some ( & last) = before. last ( ) {
304
326
for & token in before {
305
327
let token = self . 0 [ token] ;
306
- write ! ( f, r#"<span style="color:red;">-"# ) ?;
307
- pulldown_cmark_escape:: escape_html ( FmtWriter ( & mut f) , token) ?;
308
- write ! ( f, "</span>" ) ?;
328
+ self . handle_hunk_token ( & mut f, r#"<span style="color:red;">-"# , token) ?;
309
329
}
310
330
if !self . 0 [ last] . ends_with ( '\n' ) {
311
331
writeln ! ( f) ?;
@@ -315,9 +335,7 @@ impl UnifiedDiffPrinter for HtmlDiffPrinter<'_> {
315
335
if let Some ( & last) = after. last ( ) {
316
336
for & token in after {
317
337
let token = self . 0 [ token] ;
318
- write ! ( f, r#"<span style="color:green;">+"# ) ?;
319
- pulldown_cmark_escape:: escape_html ( FmtWriter ( & mut f) , token) ?;
320
- write ! ( f, "</span>" ) ?;
338
+ self . handle_hunk_token ( & mut f, r#"<span style="color:green;">+"# , token) ?;
321
339
}
322
340
if !self . 0 [ last] . ends_with ( '\n' ) {
323
341
writeln ! ( f) ?;
0 commit comments