rtfpessoa / diff2html

Pretty diff to html javascript library (diff2html)
https://diff2html.xyz
MIT License
2.87k stars 278 forks source link

Allow line breaks in side-by-side view #99

Open jung-kim opened 8 years ago

jung-kim commented 8 years ago

Allow line breaks in side-by-side view to see the code without the need to scroll horizontally.

Check https://github.com/mohanapreeya/diff2html for an example.


Thank for a quick response on #97 and we do have word wrap working in default view but not in side by side view. Wordwrap view has always been challenging in side by side view but I figure I would use this time to describe the problem.

Side by side view with wordwrap is challenging because when word is wrapped in one table, that height needs to be applied to another table. For example, in below right table's words are wrapped and caused increase in row height but it cannot be easily be applied to left table as they are separate table.

screen shot 2016-09-11 at 15 06 32

Will it be easy to place them in a same table so we can easily do this without JS? I feel like this will not be a trivial change and I think this maybe not be a critical issue.

rtfpessoa commented 8 years ago

That is probably the biggest layout problem. Even for the line-by-line view it is hard to get the breaks correctly.

For the side-by-side, having only one table, I am not sure if you can make the widths and the overflows work, and even harder to have horizontal scroll working.

If you have any suggestions. I can take a look, but this is quite difficult.

rtfpessoa commented 7 years ago

Related to #86

thinkpozzitive commented 7 years ago

@codingtwinky what changes did you make in order to get "word wrap working in default view"? Can you show me an example?

mohanapreeya commented 5 years ago

I have solved this issue in my worspace with some new template files and code changes. I would like to contribute my changes.

rtfpessoa commented 5 years ago

@mohanapreeya that would be nice. Can I check the working version somewhere?

mohanapreeya commented 5 years ago

I have a temporary output in this fork https://github.com/mohanapreeya/diff2html.git. You can view the output in demo page. Source code changes are in the same repository.

hungdev commented 5 years ago

@jung-kim could you tell me how to break word like your image? i don't need make it side by side. please tell me.

jung-kim commented 5 years ago

You mean wordwrap?

hungdev commented 5 years ago

@jung-kim yes, which class should i override overflow-wrap: break-word;? or how do i do to make like your image?

jung-kim commented 5 years ago

I'm bit confused on what you mean by "like your image". I presume you mean the green text on the right side and if that is correct break-word is the correct one.

hungdev commented 5 years ago

@jung-kim no, my mean break the work if the sentence too long. look at the online example: https://stackblitz.com/edit/react-em2guv i dont want to horizontal scroll, i want to break line.

jung-kim commented 5 years ago

Green text on the right side is the one with line break isn't it? Either way, pick whatever settings within wordwrap that can help you

zabbixfan commented 4 years ago

I really need this feature,please

robertwalsh0 commented 4 years ago

Not sure if this works in side-by-side but in line-by-line you can get the lines to wrap by changing the following css

    .d2h-code-line, .d2h-code-line-ctn {
      white-space: normal;
    }
ccadek commented 3 years ago

@robertwalsh0 This CSS does work in side-by-side view as well.

rtfpessoa commented 3 years ago

I cannot replicate this, can you provide a working example?

NL33 commented 3 years ago

New to diff2html. It seems awesome. Thanks for the great work putting it together over the years.

Is there currently a working way to have text wrap with any of diff2html's formats?

I note that if I use diff2html on a diff, without including the mandatory html resource inputs:

<!-- CSS -->
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/diff2html/bundles/css/diff2html.min.css" />

<!-- Javascripts -->
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/diff2html/bundles/js/diff2html-ui.min.js"></script>

Then the resulting display from this code:

const Diff2html = require('diff2html');
const diffJson = Diff2html.parse([DIFF STRING TO BE DISPLAYED];
const diffHtml = Diff2html.html(diffJson, { drawFileList: true  });
document.getElementById('showTheDiff').innerHTML = diffHtml

Shows the changes with the text word-wrapped in my app. Of course, it doesn't have the color highlighting that the mandatory html resource inputs have, but I wonder if I can just add that with some css manually.

rtfpessoa commented 3 years ago

Is there currently a working way to have text wrap with any of diff2html's formats?

No, I could not find a way that does not break something else.

mensfeld commented 2 years ago

@rtfpessoa could you point out what were the problems, I did really bad POC but this looks sooo good (not side by side):

Zrzut ekranu z 2021-09-17 13-05-01

rtfpessoa commented 2 years ago

@mensfeld the problem is in the side-by-side diff. Can you make that work for side-by-side too?

mensfeld commented 2 years ago

@rtfpessoa I can give it a shot in 1-2 weeks but I'm not an expert and my solution is rather clumsy.

donaldpipowitch commented 2 years ago

Not sure if this works in side-by-side but in line-by-line you can get the lines to wrap by changing the following css

    .d2h-code-line, .d2h-code-line-ctn {
      white-space: normal;
    }

Thanks for the hint. I got even better results with this as leading whitespace in a line will be preserved:

     .d2h-code-line, .d2h-code-line-ctn {
       white-space: pre-wrap;
     }
skivol commented 2 years ago

Taking ideas from this thread (thanks for those :) ) and also overriding original "width: 100%" in some classes (which probably doesn't work well inside table cells, in combination with padding):

.d2h-code-line-ctn {
    white-space: normal;
}
.d2h-code-line, .d2h-code-side-line, .d2h-code-line-ctn {
    width: revert;
}

to avoid overflow problems like on the image below: example

And things seem to look quite good 👍

rtfpessoa commented 2 years ago

@skivol do you think you could send a full spec with all the changes required to get this to work in both side-by-side and line-by-line?

skivol commented 2 years ago

@rtfpessoa you mean the full source code of the html template which I used for the purpose (with css styles which were mentioned in the comment above) ? Can do that, but not sure if the quality of the results is sufficient for general usage (specifically in regards to the alignment of the lines to the left and right which is a bit worse when wrapping the lines, but the benefit is that everything is visible without the need to scroll horizontally).

image

I guess one could try to display both sides in one table (possibly with rowspan for changesets which differ in number of rows) in an attempt to be able to do the wrapping and keep the alignment 🤔

rtfpessoa commented 2 years ago

Ahh, ok. That not needed

abelpz commented 1 year ago

@rtfpessoa is there an open PR on this? I got it working with some CSS changes.

rtfpessoa commented 1 year ago

👋 @abelpz no, I could never get it working properly.

If you got it working in both ways, would be good if we could offer both options (with and without line breaks) maybe by applying a different css classes.

abelpz commented 1 year ago

@rtfpessoa it does work for both side-by-side and line-by-line, I could try to add that if you want, this is what I propose:

If you point me to the files I should look at to add this, I can make a PR. Or I could just share the CSS, and someone else can give it a try.

rtfpessoa commented 1 year ago

I am not sure this can be done with a single file change.

The code starts in diff2html.ts. You need to add the css in diff2html.css and then somehow apply the class change when rendering maybe by passing the boolean to the templates.

You can test if it works by running yarn validate and then opening the docs/demo.html file generated which will use the code you changed.

jsonmorris commented 4 months ago

Or I could just share the CSS, and someone else can give it a try.

@abelpz any way you could provide the CSS for defining the table width and word-wrap correctly for Side-by-side diffs?

jsonmorris commented 4 months ago

I achieved the wrap I needed for side-by-side diffs using the following CSS. Not sure if this breaks line-by-line, but looks like there are solutions for that above.

.d2h-code-line-ctn {
    white-space: pre-wrap;
    word-break: break-all;
}