MarkdownSharp & GitHub syntax for C# code

笑着哭i 提交于 2019-11-30 03:02:26

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.

As one can read in this post, GitHub relies on RedCarpet to render Markdown syntax.

However, Vicent Marti (Sundown (ex-Upskirt) and RedCarpet maintainer) states that the syntax highlighting is specifically handled by Pygments, a python library.

Back to your concern, I can think of several options to benefit from syntax highlighting from C#:

  • Try and build a compiled managed version of Pygments source code thanks to IronPython ("IronPython’s Hosting APIs can be used to compile Python scripts into DLLs, console executables, or Windows executables.")
  • Port Pygment to C#
  • Use a different syntax highlighting product (for instance, ColorCode which is used by Codeplex...)

Then either:

  • Fork MarkDownSharp to make it accept plug-ins
  • Similarly to what GitHub does, use the managed syntax highlighting product and post process the Html generated by MarkDownSharp

By the way, as a MarkDown alternative, you might want to consider Moonshine, a managed wrapper on top of Sundown which is said to be "at least 20x faster than MarkdownSharp when run against MarkdownSharp's own benchmark app."

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