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