diff2html icon indicating copy to clipboard operation
diff2html copied to clipboard

What does matching actually do?

Open akash329d opened this issue 3 years ago • 7 comments

Hi,

I've been trying to figure out what the matching option actually does, playing around with the demo here - https://diff2html.xyz/demo.html

The output always looks the same regardless of the matching option chosen.

Thanks

akash329d avatar Jun 29 '22 18:06 akash329d

@akash329d I think I might have broken in during the migration to typescript. I need to dig where I might have broken it. I think the difference was how it applied the matching algorithm.

rtfpessoa avatar Jul 24 '22 17:07 rtfpessoa

After a quick look seems like maybe it was something different. Probably I should split the matching from diffstyle.

But seems like it was some improvement to the highlight of the changes in the diff here

Need to check what changed in the diff dependency.

rtfpessoa avatar Jul 24 '22 18:07 rtfpessoa

Have been playing around with it a bit and it seems like the changedWords array is still being created correctly. Might have something to do with how it's being displayed?

As a separate comment real quick, would you be open to adding an option for the library to return JSX rather than an HTML string? (So that it could be used as a react component). I was going to create a PR but figured it would be a pretty large change (and I'm not quite sure how to structure it), so another option could be to fork the library and make a separate diff2html-react version.

akash329d avatar Jul 24 '22 18:07 akash329d

As a separate comment real quick, would you be open to adding an option for the library to return JSX rather than an HTML string? (So that it could be used as a react component). I was going to create a PR but figured it would be a pretty large change (and I'm not quite sure how to structure it), so another option could be to fork the library and make a separate diff2html-react version.

It sounds like something that could be interesting to have. What would be your idea to implement this together with the current HTML output?

rtfpessoa avatar Aug 12 '22 22:08 rtfpessoa

That's the part I wasn't totally sure on. Could make it a flag to return JSX rather than HTML string but then would need to add React as a dependency for the project, and have a some duplicate code. My plan for it was to take all of the Hogan templates and convert them to functions that return JSX. But would likely be better off forking and doing the conversion rather than having it as a flag.

akash329d avatar Aug 12 '22 23:08 akash329d

Could make it a flag to return JSX rather than HTML string but then would need to add React as a dependency for the project, and have a some duplicate code.

Why would you need react as a dependency? Are you returning actual JSX elements? Or Would you be generating a file which has JSX inside?

My plan for it was to take all of the Hogan templates and convert them to functions that return JSX.

If you plan is just to change the templates it should be trivial. You can even try it by overriding the current ones and see if it works for you.

But would likely be better off forking and doing the conversion rather than having it as a flag.

Feel free to do that to.

rtfpessoa avatar Aug 12 '22 23:08 rtfpessoa

I was planning on returning actual JSX elements, so I was thinking that React would be required for that. It might be possible to use JSX without React though. Will try just directly changing the templates and seeing how that goes.

My main goal was to make it into a React component that is easy to drop in to any React project, similar to https://github.com/praneshr/react-diff-viewer

akash329d avatar Aug 12 '22 23:08 akash329d

Closing for inactivity.

rtfpessoa avatar Aug 07 '23 14:08 rtfpessoa