feat: add wrapLines option for line-by-line and side-by-side renderers#589
Open
mohanapriyac9691 wants to merge 2 commits intortfpessoa:masterfrom
Open
feat: add wrapLines option for line-by-line and side-by-side renderers#589mohanapriyac9691 wants to merge 2 commits intortfpessoa:masterfrom
mohanapriyac9691 wants to merge 2 commits intortfpessoa:masterfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces a
wrapLinesboolean configuration option that enablesword-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
wrapLines?: booleantoRenderConfig,LineByLineRendererConfig,and
SideBySideRendererConfigwrapLines: truein both renderers;falsein the top-leveldiff2htmlconfig (opt-in at the API level)Template Architecture
generic-line.mustacheinto a row wrapper that acceptsinjected
{{{lineContent}}}, decoupling row structure from cell contentgeneric-line-content.mustachefor reusable<td>cell rendering{{#diffClass}} {{diffClass}}{{/diffClass}}conditionally onfile-diff wrappers to avoid spurious trailing spaces in class attributes
Line-by-line renderer
diffClassto template to conditionally applyd2h-wrapped-file-diffCSS classSide-by-side renderer
wrapLinesmode: render both old and new line content into theleft panel row; keep
diffs.rightempty to hide the right panelnon-wrapLines mode so context lines are not visually offset due to
a missing block-header row
CSS
flex-basis: 100%anddisplay: inlineoverrides inside.d2h-wrapped-file-diffto avoid breaking the default side-by-sidelayout
.d2h-wrapped-file-diffDemo
wrapLinesconfig 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