Diff syntax highlighting in Github Markdown

久未见 提交于 2019-12-31 10:56:14

问题


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 something specific in the code using bold or anything.

I know about <pre> etc... but it takes away my csharp highlighting.

Best case scenario - some way to highlight code in the ```csharp section.

Next best thing - I can write the code as diff - using + and - to highlight stuff, but how do I tell Github to highlight diff syntax with the red and green backcolor?

Is there a way to use both diff and csharp syntax highlighting?


回答1:


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!");
   }
}
```

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.




回答2:


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!



来源:https://stackoverflow.com/questions/40883421/diff-syntax-highlighting-in-github-markdown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!