Diff syntax highlighting in Github Markdown

前端 未结 2 454
一整个雨季
一整个雨季 2021-02-01 11:50

I\'m writing documents that should explain code in C# using Markdown.

I use the ```csharp to get csharp highlighting.

I sometimes want to highlight

相关标签:
2条回答
  • 2021-02-01 11:58

    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!

    0 讨论(0)
  • 2021-02-01 12:04

    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:

    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.

    0 讨论(0)
提交回复
热议问题