Internal helper to render content with HTML.
(&self, content: &[u8], hunks: &[ChangeHunk], class: &str)
| 533 | |
| 534 | /// Internal helper to render content with HTML. |
| 535 | fn render_with_html(&self, content: &[u8], hunks: &[ChangeHunk], class: &str) -> String { |
| 536 | let mut result = String::new(); |
| 537 | |
| 538 | for hunk in hunks { |
| 539 | let text = String::from_utf8_lossy(hunk.extract(content)); |
| 540 | // Escape HTML entities |
| 541 | let escaped = html_escape(&text); |
| 542 | |
| 543 | if hunk.is_change() { |
| 544 | result.push_str(&format!( |
| 545 | "<span class=\"diff-{}\">{}</span>", |
| 546 | class, escaped |
| 547 | )); |
| 548 | } else { |
| 549 | result.push_str(&escaped); |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | result |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | /// Escape HTML special characters. |
no test coverage detected