用于源代码格式化的 C#/.NET 库,例如 Stack Overflow 使用的库?
我正在编写一个命令行工具来将 Markdown 文本转换为 html 输出,这看起来很简单。
然而,我想知道如何为嵌入式代码块获得漂亮的语法着色,就像 Stack Overflow 使用的那样。
有谁知道:
- StackOverflow 正在使用什么库
- ,或者是否有一个我可以轻松重用的库?
基本上,它需要拥有一些与 Stack Overflow 使用的“智能”相同的“智能”,基本上是尽最大努力找出所使用的语言来选择正确的关键字。
基本上,我想要的是让我自己的程序处理如下所示的块:
if (a == 0) return true;
if (a == 1) return false; // fall-back
我正在使用的 Markdown Sharp 库默认将上面的内容输出为简单的 pre/code html 块,没有语法着色。
我想要与 Stack Overflow 上的格式相同的处理类型,例如上面包含蓝色的“return”关键字。
或者,嗯,在添加代码示例后检查此 Stack Overflow 页面的源代码后,我注意到它的格式也类似于简单的前/代码块。它是纯粹的 javascript-magic 在这里工作吗,所以也许没有这样的库?
如果没有库可以通过所使用的关键字自动确定可能的语言,那么如果我明确告诉它该语言,是否有一个库可以工作?由于这是“我的”markdown-commandline-tool,因此如果需要,我可以轻松添加语法。
I am writing a command line tool to convert Markdown text to html output, which seems easy enough.
However, I am wondering how to get nice syntax coloring for embedded code blocks, like the one used by Stack Overflow.
Does anyone know either:
- What library StackOverflow is using
- or if there's a library out there that I can easily reuse?
Basically it would need to have some of the same "intelligence" found in the one that Stack Overflow uses, by basically doing a best-attempt at figuring out the language in use to pick the right keywords.
Basically, what I want is for my own program to handle a block like the following:
if (a == 0) return true;
if (a == 1) return false; // fall-back
Markdown Sharp, the library I'm using, by default outputs the above as a simple pre/code html block, with no syntax coloring.
I'd like the same type of handling as the formatting on Stack Overflow does, the above contains blue "return" keywords for example.
Or, hmm, after checking the source of this Stack Overflow page after adding the code example, I notice that it too is formatted like a simple pre/code block. Is it pure javascript-magic at works here, so perhaps there's no such library?
If there's no library that will automagically determine a possible language by the keywords used, is there one that would work if I explicitly told it the language? Since this is "my" markdown-commandline-tool, I can easily add syntax if I need to.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哎呀 - 我完全忽略了您已经在使用 Markdown Sharp 的事实 - 但 >是 Stack Overflow 使用的 Markdown 处理器。
不过,它也使用Google Code Prettify -这就是提供颜色的部分。这就是你所缺少的吗?
Oops - I completely missed the fact that you're already using Markdown Sharp - but that is the Markdown processor Stack Overflow uses.
However, it also uses Google Code Prettify - and that's the bit that provides the colors. Is that the bit you were missing?