Skip to content

Add opt-in line wrapping to both diff layouts - #609

Merged
rtfpessoa merged 4 commits into
masterfrom
rodrigo/opt-in-line-wrapping
Nov 28, 2026
Merged

rtfpessoa merged 4 commits into
masterfrom
rodrigo/opt-in-line-wrapping

Conversation

@rtfpessoa

Copy link
Copy Markdown
Owner

Motivation

Long diff lines can force horizontal scrolling, and independently wrapping two side-by-side tables lets the rows drift out of alignment. Add wrapLines: true in both existing formats without changing the default output. The paired-row design builds on Mohana Priya's work in #589; #563 is prior art.

How it works

  • wrapLines defaults to false. Line-by-line adds a scoped CSS marker when enabled. Side-by-side reuses prepared line pairs and writes both sides into one row, so the next pair starts below the taller side.
  • The demo control works independently of layout and restores from ?wrapLines=true. Only the latest request may update the preview. Wrapping styles stay inside their own diff, including when a custom info message contains another diff.

Verification

  • Locked Linux build: 127 tests and 76 unchanged snapshots.
  • Compared the exact packed base and head using real Git diffs: 252 exact default/off HTML matches; all 34 external CLI cases matched in logical HTML, DOM, and PNG across both layouts.
  • Chrome 158: 32 default widget/demo DOM and PNG pairs matched. All 12 wrapping geometry cases and 15 demo/nesting/info regressions passed. At the tested viable widths, code did not overflow and paired row tops aligned exactly. An earlier build had one 11-pixel CLI capture difference that did not reproduce in 16 diagnostic captures or on this head.

Review focus

Check the paired table and CSS scoping: the opt-in DOM differs, and selection may span both columns. Custom line-by-line templates need the wrapping marker to opt in. No new layout, CLI flag, dependency, or JavaScript row sizing. Other browser engines, assistive technology, and live clipboard behavior were not verified.

Keep the existing markup and templates for unwrapped diffs. Add a
line-by-line wrapping modifier and emit each prepared side-by-side
pair into one table row, so the taller side determines row height.
Expose the option in the demo and preserve it across redraws.

The paired rows build on Mohana Priya's design in #589, with #563
as prior art.

Signed-off-by: Rodrigo Fernandes <rodrigo.fernandes@datadoghq.com>
Use one generation-guarded request per demo redraw.

Scope wrap rules to the owning table and isolate nested diff widgets.

Signed-off-by: Rodrigo Fernandes <rodrigo.fernandes@datadoghq.com>
Signed-off-by: Rodrigo Fernandes <rodrigo.fernandes@datadoghq.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Deploying diff2html with  Cloudflare Pages  Cloudflare Pages

Latest commit: b2505fa
Status: ✅  Deploy successful!
Preview URL: https://04fb5013.diff2html.pages.dev
Branch Preview URL: https://rodrigo-opt-in-line-wrapping.diff2html.pages.dev

View logs

Signed-off-by: Rodrigo Fernandes <rodrigo.fernandes@datadoghq.com>
@rtfpessoa
rtfpessoa marked this pull request as ready for review November 28, 2026 16:42
@rtfpessoa
rtfpessoa merged commit 74c3703 into master Nov 28, 2026
8 checks passed
@rtfpessoa
rtfpessoa deleted the rodrigo/opt-in-line-wrapping branch November 28, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant