Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MarkdownSharp & GitHub syntax for C# code

Is there a way to get MarkdownSharp (I'm using the NuGet package) to handle 'GitHub flavored Markdown (GFM)' and especially syntax highlighting of c# code, which (in GFM) is written like this:

```c# //my code..... ``` 

So, if I pass Markdown formatted content to MarkDownSharp, containg a C# code block (as above) I want it to generate syntax highlighted html for that c# code. Any ideas? I know I can use the supported 4 spaces to indicate a code block, but again, I'm seeking a solution for getting it to support GitHub flavored Markdown.

like image 535
Daniel Avatar asked Nov 21 '11 11:11

Daniel


2 Answers

I have made some light modifications to MarkdownSharp that will transform github flavored fenced code blocks

https://github.com/KyleGobel/MarkdownSharp-GithubCodeBlocks

```cs Console.WriteLine("Fenced code blocks ftw!"); ``` 

Would become

<pre><code class='language-cs'> Console.WriteLine("Fenced code blocks ftw!"); </code></pre> 

It handles the cases I needed to use, there are probably lots of edge cases though, feel free to fork/change/modify/pull request. Markdown sharp has plenty of comments and is all only one file, so it's not too bad to modify.

like image 139
Kyle Gobel Avatar answered Oct 06 '22 12:10

Kyle Gobel


Here's the result: https://github.com/danielwertheim/kiwi/wiki/Use-with-Asp.Net-MVC

//D

like image 30
Daniel Avatar answered Oct 06 '22 13:10

Daniel