So I wrote a Insertcode plugin for FCKeditor. The process of making the whole plugin is very simple:
FCKeditor Plugin Development Please refer to the FCKeditor official website Documentation:
Http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Customization/Plug-ins
First, we create a new Insertcode directory under the Fckeditor/editor/plugins directory and create a new Fckplugin.js file in the Insertcode directory.
Insert the following code in the new Fckplugin.js file:
Inserting code
Copy Code code as follows:
Fckcommands.registercommand (' Insertcode ', New Fckdialogcommand (' Insertcode ', Fcklang.insertcode, FCKPlugins.Items[ ' Insertcode ']. Path + ' insertcode.aspx ', 700, 600);
var insertcodeitem = new Fcktoolbarbutton (' Insertcode ', fcklang[' insertcode ');
Insertcodeitem.iconpath = fckplugins.items[' Insertcode ']. Path + ' images/insertcode.gif ';
Fcktoolbaritems.registeritem (' Insertcode ', insertcodeitem);
Create the Images,lang,languages directory under the Fckeditor/editor/plugins/insertcode directory and new en.js,zh-cn.js in the Lang directory. The contents of the En.js are:
Fcklang.insertcode = ' Insert codes ';
The contents of the Zh-cn.js are:
Fcklang.insertcode = ' Insert code ';
Download Codehighlighter http://www.jb51.net/codes/94.html
Control and unpack, put the Codehighlighter/bin directory under the Actiprosoftware.codehighlighter.net20.dll,actiprosoftware.shared.net20.dll, CodeHighlighterTest.dll three DLLs to the Blogengine.web/bin directory,
Copy the Lexers entire directory in codehighlighter/languages to the Fckeditor/editor/plugins/insertcode/languages directory,
Copy all the pictures in the codehighlighter/images/outliningindicators/directory to the Fckeditor/editor/plugins/insertcode/images directory. and save this picture download to fckeditor/editor/plugins/insertcode/images/insertcode.gif.
Create a new insertcode.aspx in the fckeditor/editor/plugins/insertcode/directory, and note that if you are new with Visual Studio
Insertcode.aspx contents are as follows:
Copy Code code as follows:
<%@ Page language= "C #" validaterequest= "false"%>
<%@ Register tagprefix= "CH" namespace= "Actiprosoftware.codehighlighter" assembly= " ActiproSoftware.CodeHighlighter.Net20 "%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<script runat= "Server" >
static string code = String. Empty;
protected void btnSubmit_Click (object sender, EventArgs e)
... {
Code = Txtcode.text;
Highlighter.languagekey = DdlLangType.SelectedItem.Text;
highlighter.outliningenabled = chkoutlining.checked;
highlighter.linenumbermarginvisible = chklinenum.checked;
Highlighter.text = code;
}
protected void Page_Load (object sender, EventArgs e)
... {
if (! Page.IsPostBack)
... {
codehighlighterconfiguration config = (codehighlighterconfiguration) configurationmanager.getsection (" Codehighlighter ");
String[] keys = new string[config. LanguageConfigs.Keys.Count];
Config. LanguageConfigs.Keys.CopyTo (Keys, 0);
Array.Sort (keys);
foreach (string key in keys)
... {
DDLLANGTYPE.ITEMS.ADD (key);
}
Ddllangtype.selectedindex = DdlLangType.Items.IndexOf (DdlLangType.Items.FindByText ("C #"));
}
}
protected void Codehighlighter_postrender (object sender, EventArgs e)
... {
if (!string. IsNullOrEmpty (Highlighter.output))
... {
Lblcode.text = Highlighter.Output.Replace ("", ""). Replace ("\ n", "<br/>");
Response.Write ("<SCR" + "Ipt>window.parent.setokbutton (true); </SCR" + "ipt>");
}
}
</script>
<title>insertcode by moozi.net</title>
<script src= "Http://www.cnblogs.com/dialog/common/fck_dialog_common.js" type= "Text/javascript" ></script >
<script type= "Text/javascript" >
var oeditor = window.parent.InnerDialogLoaded ();
Gets the document DOM
var ODOM = oEditor.FCK.EditorDocument;
var oactiveel = oEditor.FCKSelection.GetSelectedElement ();
Window.onload = function ()
... {
Window.parent.SetOkButton (FALSE);
}
function Ok ()
... {
if (Gete (' Txtcode '). Value = = ")
... {
Alert ("Code content cannot be empty!") ");
return false;
}
OEditor.FCK.InsertHtml (document.getElementById ("Lblcode"). InnerHTML);
return true;
}
</script>
<style type= "Text/css" >
. langtype
... {
padding-bottom:5px;
}
. btnrun
... {
padding-top:5px;
Text-align:right;
}
Pre
... {
Background-color: #f4f4f4;
Border-style:solid;
border-width:1px;
Border-color: #C0C0C0;
Font-family:courier New, monospace;
font-size:10pt;
}
</style>
<body>
<form id= "Form1" runat= "Server" >
<div>
<div class= "Langtype" >
Language type: <asp:dropdownlist id= "Ddllangtype" runat= "Server" >
</asp:DropDownList>
<asp:checkbox id= "chkoutlining" text= "Collapsing Code" runat= "Server" checked= "true"/>
<asp:checkbox id= "Chklinenum" text= "Allow line number" runat= "Server" checked= "false"/>
</div>
<div>
<asp:textbox id= "Txtcode" runat= "Server" Textmode= "Multiline" width= "640px" height= "390px" ></asp:textbox >
</div>
<div class= "Btnrun" >
<asp:button id= "btnsubmit" runat= "Server" text= "Convert" onclick= "btnSubmit_Click"/>
<pre id= "Pre1" style= "Display:none;" >
<ch:codehighlighter runat= "Server" id= "highlighter" onpostrender= "Codehighlighter_postrender"/>
</pre>
<asp:label id= "Lblcode" style= "Display:none;" runat= "Server" ></asp:Label>
</div>
</div>
</form>
</body>
Next modify Fckeditor/fckconfig.js, in the original file we can find//FCKConfig.Plugins.Add (' autogrow '), this code, In the next line of code insert: FCKCONFIG.PLUGINS.ADD (' Insertcode ', ' zh-cn,en ');
Last modified Web.config file: (Please refer to codehighlighter/web.config)
Insert in <configuration>:
<configSections>
<section name= "Codehighlighter" requirepermission= "false" type= " ActiproSoftware.CodeHighlighter.CodeHighlighterConfigurationSectionHandler, ActiproSoftware.CodeHighlighter.Net20 "/>
</configSections>
After <system.web></system.web> insert:
<codeHighlighter>
<cache languagetimeout= "3"/>
<keywordlinking enabled= "true" target= "_blank" defaultkeywordcollectionkey= "actiprokeywords" >
<keywordcollection key= "Actiprokeywords" >
<explicitkeyword tokenkey= "Identifiertoken" patternvalue= "Actipro" url= "http://www.actiprosoftware.com" Casesensitive= "false"/>
<explicitkeyword tokenkey= "Identifiertoken" patternvalue= codehighlighter "url=" http://www.codehighlighter.com "Casesensitive= false"/>
</keywordCollection>
</keywordLinking>
<languages>
<language key= "Assembly" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.Assembly.xml "/>
<language key= "Batchfile" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.BatchFile.xml "/>
<language key= "C #" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.CSharp.xml "/>
<language key= "CSS" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.CSS.xml "/>
<language key= "HTML" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.HTML.xml "/>
<language key= "INIFile" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.INIFile.xml "/>
<language key= "Java" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.Java.xml "/>
<language key= "JScript" definitionpath= ~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.JScript.xml "/>
<language key= "Lua" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.Lua.xml "/>
<language key= "MSIL" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.MSIL.xml "/>
<language key= "Pascal" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.Pascal.xml "/>
<language key= "Perl" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.Perl.xml "/>
<language key= "PHP" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.PHP.xml "/>
<language key= "PowerShell" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.PowerShell.xml "/>
<language key= "Python" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.Python.xml "/>
<language key= "SQL" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.SQL.xml "/>
<language key= "vb.net" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.VBDotNet.xml "/>
<language key= "VBScript" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.VBScript.xml "/>
<language key= "XAML" definitionpath= ~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.XAML.xml "/>
<language key= "XML" definitionpath= "~/fckeditor/editor/plugins/insertcode/languages/lexers/ ActiproSoftware.XML.xml "/>
</languages>
<linenumbermargin forecolor= "Teal" paddingcharacter= "" visible= "true"/>
<outlining enabled= "true" imagespath= "~/fckeditor/editor/plugins/insertcode/images/"/>
<spacesintabs count= "4"/>
</codeHighlighter>
This time the plugin is finished. This method can be said to be once and for all, later replace the high version of the FCKeditor, only need to modify fckconfig.js to add this plugin can be