程序代码语法加亮插件比较

来源:互联网 发布:js ajax java实例 编辑:程序博客网 时间:2024/05/17 03:11

Note: this entry has moved.

程序代码语法加亮插件是写BLOG程序员的必选,我试用过多款插件,最终选定功能比较强大的有两款:Code Syntax HighlighterSource Code Formatter,看我BLOG的人可以知道,我以前的BLOG一直使用Source Code Formatter,那是因为一直没有试用Code Syntax Highlighter,通过比较我发现Code Syntax Highlighter的表现力更好,以下是一个简单的比较:

Source Code Formatter的C#效果,选中了自动折行和带行号:

1 public override object SaveState(object container) 2 { 3 XmlDocument document = (XmlDocument)container; 4 XmlElement element = (XmlElement)base.SaveState(container); 5 6 // Save settings. 7 XmlElement nodeRootElement = document.CreateElement("nodes"); 8 element.AppendChild(nodeRootElement); 9 10 this.StoreNode(document, nodeRootElement, this.xmlSpecialCharNode, "SpecialCharNode");11 this.StoreNode(document, nodeRootElement, this.xmlTagNode, "TagNode");12 this.StoreNode(document, nodeRootElement, this.xmlNamespaceNode, "NamespaceNode");13 this.StoreNode(document, nodeRootElement, this.xmlCommentNode, "CommentNode");14 this.StoreNode(document, nodeRootElement, this.xmlAttributeNameNode, "AttributeNameNode");15 this.StoreNode(document, nodeRootElement, this.xmlAttributeValueNode, "AttributeValueNode");16 17 return element;18 }

Code Syntax Highlighter的C#表现效果,选中了带行号:

1.        public override object SaveState(object container)
2.        {
3.            XmlDocument document = (XmlDocument)container;
4.            XmlElement element = (XmlElement)base.SaveState(container);
5.
6.            // Save settings.
7.            XmlElement nodeRootElement = document.CreateElement("nodes");
8.            element.AppendChild(nodeRootElement);
9.
10.            this.StoreNode(document, nodeRootElement, this.xmlSpecialCharNode, "SpecialCharNode");
11.            this.StoreNode(document, nodeRootElement, this.xmlTagNode, "TagNode");
12.            this.StoreNode(document, nodeRootElement, this.xmlNamespaceNode, "NamespaceNode");
13.            this.StoreNode(document, nodeRootElement, this.xmlCommentNode, "CommentNode");
14.            this.StoreNode(document, nodeRootElement, this.xmlAttributeNameNode, "AttributeNameNode");
15.            this.StoreNode(document, nodeRootElement, this.xmlAttributeValueNode, "AttributeValueNode");
16.
17.            return element;
18.        }

可以看出Code Syntax Highlighter的代码更紧凑,语法着色也更丰富。来看看它们的选项:

 Code
Formatter
Code
Highlighter
支持语言数1422
显示行号支持支持
显示边框不支持支持
改变背景色支持支持
自动折行支持支持
固定宽度不支持支持
自定义TAB宽度支持不支持

 

Code Syntax Highlighter的源代码有两个小问题:

1. 对中文注释的支持有问题
2. 不支持Live Writer Wave 3 Beta

前者是因为它对RTF文件的处理有点问题,后者是因为它使用的WindowsLive.Writer.Controls.BrowseButton 在Wave 3里面不再存在了。

我对代码做了修改,以上两个BUG都做了改正。

1. 修改RTF编码保证正常显示中文。
2. 使用WindowsLive.Writer.Controls.BitmapButton代替WindowsLive.Writer.Controls.BrowseButton ,同时支持14.x和15.x。
3. 同步了最新版本的Wilco SyntaxHighlighting。

Code Syntax Highlighter: 程序下载修改的源代码下载