Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diff syntax highlighting in Github Markdown

People also ask

How do you use Markdown diff?

First, instead of specifying the programming language, use diff after the backticks. Then at the beginning of any lines of code you want to show as removed, add a - . At the beginning of any lines of code you want to show as added, add a + . I have used this in tons of my coding tutorials, such as this one.

How do you get syntax highlighting in Markdown?

Many Markdown processors support syntax highlighting for fenced code blocks. This feature allows you to add color highlighting for whatever language your code was written in. To add syntax highlighting, specify a language next to the backticks before the fenced code block.

How do I highlight code in GitHub?

To link to multiple lines of highlighted code, select your first line of code and then CTRL+SHIFT click on the last line of code you want to highlight. Notice the URL is now appended with a range of line numbers (e.g. https://github.com/…/functions.php#L117-L148).


Github's markdown supports diff when formatting code. For example:

```diff
public class Hello1
{
   public static void Main()
   {
-      System.Console.WriteLine("Hello, World!");
+      System.Console.WriteLine("Rock all night long!");
   }
}
```

Output:

enter image description here

and it should give you the Diff looks you are looking for, highlighting in red what has been removed and in green what has been added.


Salvador's response is correct, however, I found out that you should add the diff header to the code snippet in order to highlight it:

``` diff
diff --git a/filea.extension b/fileb.extension
index d28nd309d..b3nu834uj 111111
--- a/filea.extension
+++ b/fileb.extension
@@ -1,6 +1,6 @@
-oldLine
+newLine
```

I hope that helps!