TextFile Comparer in C# using DiffMatchPatch trimming leading spaces issue

470 Views Asked by At

I was using https://github.com/google/diff-match-patch in my C# project to compare text files. Dump the difference into html and send it as an email body to my mail in case when difference was found. The way I'm using is the following:

var dump = DiffMatchPatchModule.Default;
var diffs = dump.DiffMain(linesOrigin, linesRemoved);
var beforeHtml = dump.DiffPrettyHtml(diffs);

but I've spotted that when I add/remove leading spaces nothing is highlighted because it trims all leading spaces, tags INS and DEL are added to html, and they are added only if a difference was spotted. So for example if I compare .py files I can see the changes in the files itself but I can't use it right away from my html file because of missing spaces.

Here is the example of html file that was generated when I've added and removed some spaces from text:

<INS STYLE="background:#07792D;" TITLE="i=0">   </INS>
<SPAN TITLE="i=3">this one starts from symbol&para;<BR></SPAN>
<DEL STYLE="background:#710505;" TITLE="i=31">  </DEL>
<SPAN TITLE="i=31">this one starts from tab&para;<BR> this one starts from space&para;<BR></SPAN>
<INS STYLE="background:#07792D;" TITLE="i=84">  </INS>
<SPAN TITLE="i=85">this is an indicator line</SPAN>

Can someone help with the way to avoid trimming of leading spaces?

0

There are 0 best solutions below