Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: GitHub markdown compatible diffs #325

Closed
edjshelton opened this issue Oct 19, 2023 · 3 comments · Fixed by #358
Closed

Feature request: GitHub markdown compatible diffs #325

edjshelton opened this issue Oct 19, 2023 · 3 comments · Fixed by #358

Comments

@edjshelton
Copy link

Small feature request:

I'd like to include the output of dyff in a code block in a PR comment using GitHub markdown's diff formatter for colorized output:

https://gist.github.com/salmedina/ad8bea4f46de97ea132f71b0bca73663#file-markdowndiffexample-md

But, presumably due to indentation, dyff diffs do not get colorized. Perhaps an option to skip indenting the diff would be useful for compatibility here.

@HeavyWombat
Copy link
Member

I like the idea. Definitely something I want to look into. To be honest, I am not happy with the internal design in retrospect, because I originally setup the report output in a way that one can extend it with other output styles, but I think it needs a bit of a redesign. Maybe I take this idea as an incentive to just that.

@begemotik
Copy link

Faced a similar case with Gitlab commenting, would be very helpful to somehow configure that kind of behavior.

@peschmae
Copy link
Contributor

I spent some time thinking about this and playing around with the code a bit and I think the Markdown report should be considered an extension/special case of a human readable report, as it will still be read by humans, but needs to follow some very specific requirements to fit the diff syntax highlighting in most markdown code blocks.

On Github there are 6 supported types of text in a diff codeblock

Regular text 
# comment style
@@ bold and pink @@
- Removal
+ Addition
! orange

What they all have in common is, that the modifier needs to be at the beginning of the line, so the indendated output of the human report would need some changes.
Additionally, since all those tools only allow highlighting a whole line, the table style form the human report doesn't make a lot of sense.

A quick check in Gitea/Forgejo and GitLab show, that they both don't differentiate between comment and regular text.
GitLab doesn't support the @@ and ! styles but has an additional = style.
Gitea/Forgejo does support @@and the = style as well.

So, while it's not really an option to support all those tools with a single Report style, creating one for GitHub should be possible, and maybe it's enough to replace the @@ with = for gitlab to make it look nice there as well.

Based on this I did a quick try, to make the indentation for the HumanReport configurable, and create a MarkdownReport with the indentation set 0 and the table mode always disabled.

Here is a comparison of an regular output, and my quick hack with just the indentation changed: https://gist.github.com/peschmae/15da258a2c6831aca691b5dc9bc691be

For very simple changes, this already works, but a lot of cases (multiline, removal of a document, and a few more) aren't solved yet.

I did one more try, where I prepended the whole addition/removal output with the corresponding sign, and removed the +/- signs for those changes, to not flag them as a diff, and I think this could be a way to move forward: https://gist.github.com/peschmae/e482f72c677c87afce1eec7364db8869

In #325 (comment) it's mentioned that the internal design of reports might be refactored, is that something that is ongoing, or should I give it a try, to implment a Markdown report based on the current HumanReport?

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 a pull request may close this issue.

4 participants