是否有一個使用C#編寫的開源項目,它可以以與shjs類似的方式將語法突出顯示應用於各種語言?靈活的語法高亮寫在C#
下面是一些僞代碼:
public string HighlightSourceInHTML(string html) {
return Highlighter.HighlightHTML(html);
}
當輸入HTML是沿着線的東西:
<!DOCTYPE html>
<html>
<head>...</head>
<body>
<p>Here is a function written using C#:</p>
<pre class="source lang-csharp">public void foo(int a, int b) {
return a + b;
}</pre>
<p>Here is the same function written using JavaScript:</p>
<pre class="source lang-javascript">function foo(a, b) {
return a + b;
}</pre>
</body>
</html>
當上述將基本上返回整個HTML文件,其中所有pre
元素與類別source
在源語言被定義的地方突出顯示語法
否te:這不是服務器端腳本,而是性能不太重要的離線應用程序的一部分。
我要建議[Pygments來做](http://pygments.org/)(這是什麼Ma9ic的答案使用),其是用Python編寫的。語法突出顯示器*是否用C#編寫?有許多用其他語言書寫的語法熒光筆:[Google code prettify](http://code.google.com/p/google-code-prettify/),[highlight.js](http:// softwaremaniacs。 org/soft/highlight/en /)和[SyntaxHighlighter](http://alexgorbatchev.com/SyntaxHighlighter/)等等。 – Chris 2012-07-27 08:39:50