samzmann
samzmann

Reputation: 2576

How to format git insertions/deletions in GitHub markdown?

I'm commenting on a GitHub issue and would like to suggest an edit to code posted in a previous comment. How can I format my markdown to highlight code to be removed in red and code to be added in green, like in git commit change summaries?

I've done this before but maybe not in GitHub, so is this even possible?

This kind of styling

Upvotes: 6

Views: 3046

Answers (2)

Waylan
Waylan

Reputation: 42637

The color is added by syntax highlighting a diff. Therefore, create a code block with diff as the "language":

```diff
  Unchanged Line
- Removed Line
+ Added Line
```

Notice that unchanged lines should be indented by two spaces. removed lines should be prefixed by a hyphen and a space, and added lines should be prefixed by a plus sign and a space. If you are making complex changes, it may be best to use a diff tool to create the diff.

Github will then run that code block through their syntax highlighter and color the lines for you. You can see an example here (also see the raw document).

Here's a screenshot of what that looks like:

Exmple diff code block

Upvotes: 20

rasengan__
rasengan__

Reputation: 987

I don't reckon we can do this on GitHub. Though you could maybe make a table and suggest changes as told here. GitHub comments actually don't have true markdown (you can even use HTML in your markdown which would've maybe allowed you to do what you desired).

Or a simple way would be to just say:

Hey , I think instead of:

insert code

we can do:

insert code

What do you think?

Best

Upvotes: 0

Related Questions