昨天已经将BlogEngine的可视化编辑器换成了FCKeditor,作为一个程序员,在博客中插入代码是很重要的一块。网上现有的都是修改FCKeditor的fckeditorcode_gecko.jsfckeditorcode_ie.js以达到InsertCode的目的。这个方法非常麻烦,当要使用FCKeditor新版本时都要重新修改这两个文件,非常影响我们的效率。所以就为FCKeditor写了个InsertCode的插件。整个插件的制作过程非常简单:

 

FCKeditor插件开发请参考FCKeditor官网的文档:

http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Customization/Plug-ins
首先,我们在FCKeditor/editor/plugins目录下新建一个insertcode目录,并在insertcode目录下新建一个fckplugin.js文件。
        在新建的fckplugin.js文件中插入下面的代码:

为FCKeditor开发代码高亮插件//插入代码
为FCKeditor开发代码高亮插件
FCKCommands.RegisterCommand('InsertCode', new FCKDialogCommand('InsertCode', FCKLang.InsertCode, FCKPlugins.Items['insertcode'].Path + 'insertcode.aspx', 700, 600)) ;
为FCKeditor开发代码高亮插件
var insertcodeItem = new FCKToolbarButton('InsertCode', FCKLang['InsertCode']) ;
为FCKeditor开发代码高亮插件insertcodeItem.IconPath
= FCKPlugins.Items['insertcode'].Path + 'images/insertcode.gif';
为FCKeditor开发代码高亮插件FCKToolbarItems.RegisterItem(
'InsertCode', insertcodeItem);
 

FCKeditor/editor/plugins/insertcode目录下创建imageslanglanguages目录,在lang目录下新建en.js,zh-cn.jsen.js的内容为:
FCKLang.InsertCode   = 'Insert Codes' ;
zh-cn.js的内容为:
FCKLang.InsertCode   = '插入代码' ;
下载CodeHighlighter(http://www.actiprosoftware.com/Download/Freeware.aspx?ProductGroupKey=CH)控件并解压,把CodeHighlighter/bin目录下的ActiproSoftware.CodeHighlighter.Net20.dll,ActiproSoftware.Shared.Net20.dll,CodeHighlighterTest.dll三个DLL复制到BlogEngine.Web/bin目录,
CodeHighlighter/Languages里的Lexers整个目录复制到FCKeditor/editor/plugins/insertcode/languages目录,
CodeHighlighter/Images/OutliningIndicators/目录下的所有图片复制到FCKeditor/editor/plugins/insertcode/images目录,并将为FCKeditor开发代码高亮插件这个图片下载保存到FCKeditor/editor/plugins/insertcode/images/insertcode.gif

FCKeditor/editor/plugins/insertcode/目录下新建insertcode.aspx,注意,如果是用Visual Studio新建的话

为FCKeditor开发代码高亮插件

insertcode.aspx内容如下:

为FCKeditor开发代码高亮插件<%@ Page Language="C#" ValidateRequest="false" %>
为FCKeditor开发代码高亮插件
为FCKeditor开发代码高亮插件
<%@ Register TagPrefix="CH" Namespace="ActiproSoftware.CodeHighlighter" Assembly="ActiproSoftware.CodeHighlighter.Net20" %>
为FCKeditor开发代码高亮插件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
为FCKeditor开发代码高亮插件
为FCKeditor开发代码高亮插件
<script runat="server">
为FCKeditor开发代码高亮插件    
static string code = string.Empty;
为FCKeditor开发代码高亮插件
为FCKeditor开发代码高亮插件    
protected void btnSubmit_Click(object sender, EventArgs e)
 

接下来修改FCKeditor/fckconfig.js,在原文件中我们能找到// FCKConfig.Plugins.Add( 'autogrow' ) ;这段代码,在这段代码下一行插入:FCKConfig.Plugins.Add( 'insertcode' , 'zh-cn,en'  ) ;

最后修改Web.config文件:(请参考CodeHighlighter/Web.config)
在<configuration>里插入:

为FCKeditor开发代码高亮插件<configSections>
为FCKeditor开发代码高亮插件    
<section name="codeHighlighter" requirePermission="false" type="ActiproSoftware.CodeHighlighter.CodeHighlighterConfigurationSectionHandler, ActiproSoftware.CodeHighlighter.Net20" />
为FCKeditor开发代码高亮插件
</configSections>
 

 

在<system.web></system.web>后插入:

为FCKeditor开发代码高亮插件<codeHighlighter>
为FCKeditor开发代码高亮插件  
<cache languageTimeout="3" />
为FCKeditor开发代码高亮插件  
<keywordLinking enabled="true" target="_blank" defaultKeywordCollectionKey="ActiproKeywords">
为FCKeditor开发代码高亮插件    
<keywordCollection key="ActiproKeywords">
为FCKeditor开发代码高亮插件      
<explicitKeyword tokenKey="IdentifierToken" patternValue="Actipro" url="http://www.actiprosoftware.com" caseSensitive="false" />
为FCKeditor开发代码高亮插件      
<explicitKeyword tokenKey="IdentifierToken" patternValue="CodeHighlighter" url="http://www.codehighlighter.com" caseSensitive="false" />
为FCKeditor开发代码高亮插件    
</keywordCollection>
为FCKeditor开发代码高亮插件  
</keywordLinking>
为FCKeditor开发代码高亮插件  
<languages>
为FCKeditor开发代码高亮插件    
<language key="Assembly" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.Assembly.xml" />
为FCKeditor开发代码高亮插件    
<language key="BatchFile" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.BatchFile.xml" />
为FCKeditor开发代码高亮插件    
<language key="C#" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.CSharp.xml" />
为FCKeditor开发代码高亮插件    
<language key="CSS" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.CSS.xml" />
为FCKeditor开发代码高亮插件    
<language key="HTML" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.HTML.xml" />
为FCKeditor开发代码高亮插件    
<language key="INIFile" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.INIFile.xml" />
为FCKeditor开发代码高亮插件    
<language key="Java" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.Java.xml" />
为FCKeditor开发代码高亮插件    
<language key="JScript" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.JScript.xml" />
为FCKeditor开发代码高亮插件    
<language key="Lua" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.Lua.xml" />
为FCKeditor开发代码高亮插件    
<language key="MSIL" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.MSIL.xml" />
为FCKeditor开发代码高亮插件    
<language key="Pascal" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.Pascal.xml" />
为FCKeditor开发代码高亮插件    
<language key="Perl" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.Perl.xml" />
为FCKeditor开发代码高亮插件    
<language key="PHP" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.PHP.xml" />
为FCKeditor开发代码高亮插件    
<language key="PowerShell" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.PowerShell.xml" />
为FCKeditor开发代码高亮插件    
<language key="Python" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.Python.xml" />
为FCKeditor开发代码高亮插件    
<language key="SQL" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.SQL.xml" />
为FCKeditor开发代码高亮插件    
<language key="VB.NET" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.VBDotNet.xml" />
为FCKeditor开发代码高亮插件    
<language key="VBScript" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.VBScript.xml" />
为FCKeditor开发代码高亮插件    
<language key="XAML" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.XAML.xml" />
为FCKeditor开发代码高亮插件    
<language key="XML" definitionPath="~/fckeditor/editor/plugins/insertcode/languages/lexers/ActiproSoftware.XML.xml" />
为FCKeditor开发代码高亮插件  
</languages>
为FCKeditor开发代码高亮插件  
<lineNumberMargin foreColor="Teal" paddingCharacter=" " visible="true" />
为FCKeditor开发代码高亮插件  
<outlining enabled="true" imagesPath="~/fckeditor/editor/plugins/insertcode/images/" />
为FCKeditor开发代码高亮插件  
<spacesInTabs count="4" />
为FCKeditor开发代码高亮插件
</codeHighlighter>
 

这次的插件就完工了。这种方法可以说是一劳永逸,以后更换高版本的FCKeditor时,只需要修改fckconfig.js将这个插件加入就可以了为FCKeditor开发代码高亮插件

相关文章: