Skip to content

feat: add wrapLines option for line-by-line and side-by-side renderers#589

Open
mohanapriyac9691 wants to merge 2 commits intortfpessoa:masterfrom
mohanapriyac9691:master
Open

feat: add wrapLines option for line-by-line and side-by-side renderers#589
mohanapriyac9691 wants to merge 2 commits intortfpessoa:masterfrom
mohanapriyac9691:master

Conversation

@mohanapriyac9691
Copy link
Copy Markdown

@mohanapriyac9691 mohanapriyac9691 commented Mar 27, 2026

Summary

Introduces a wrapLines boolean configuration option that enables
word-wrapping of diff content instead of horizontal overflow. This
feature is useful for viewing diffs on narrow viewports or when
long lines make the diff hard to read.

Changes

Configuration

  • Add wrapLines?: boolean to RenderConfig, LineByLineRendererConfig,
    and SideBySideRendererConfig
  • Default wrapLines: true in both renderers; false in the top-level
    diff2html config (opt-in at the API level)

Template Architecture

  • Refactor generic-line.mustache into a row wrapper that accepts
    injected {{{lineContent}}}, decoupling row structure from cell content
  • Add new generic-line-content.mustache for reusable <td> cell rendering
  • Apply {{#diffClass}} {{diffClass}}{{/diffClass}} conditionally on
    file-diff wrappers to avoid spurious trailing spaces in class attributes

Line-by-line renderer

  • Pass diffClass to template to conditionally apply
    d2h-wrapped-file-diff CSS class

Side-by-side renderer

  • In wrapLines mode: render both old and new line content into the
    left panel row; keep diffs.right empty to hide the right panel
  • Fix: render an aligned empty header row on the right panel in
    non-wrapLines mode so context lines are not visually offset due to
    a missing block-header row

CSS

  • Scope flex-basis: 100% and display: inline overrides inside
    .d2h-wrapped-file-diff to avoid breaking the default side-by-side
    layout
  • Add word-break, white-space, and line-number height rules scoped to
    .d2h-wrapped-file-diff

Demo

  • Add "Wrap Lines" checkbox to the demo page wired to the wrapLines
    config option

Testing

All 100 existing tests pass. Snapshots updated to reflect the new
template structure (row/cell separation and conditional CSS class).

Run tests with:
npm run test:coverage

Raised a PR long back when i started coding but didn't find time to refine it then.

Closes #99

Introduce a new `wrapLines` configuration option that enables word-wrap
display for diff output. When enabled, lines wrap at the container
boundary instead of overflowing horizontally.

Changes:
- Add `wrapLines` boolean config to render-utils, line-by-line-renderer,
  side-by-side-renderer, and diff2html default config
- Refactor mustache templates to separate row wrapping (generic-line)
  from cell content (generic-line-content), enabling flexible composition
- Apply `d2h-wrapped-file-diff` CSS class conditionally to activate
  word-break and white-space styles scoped to wrapped mode only
- Fix side-by-side view to render an aligned empty header row on the
  right panel so context lines are not visually offset
- Add wrapLines checkbox to the demo page UI
- Update test snapshots to reflect new template structure
Update the demo UI label and the CSS section comment to use the
canonical "Wrap Lines" name, consistent with the `wrapLines`
config option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow line breaks in side-by-side view

1 participant