麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 編程 > .NET > 正文

asp.net 為FCKeditor開發代碼高亮插件實現代碼

2024-07-21 02:53:25
字體:
來源:轉載
供稿:網友
昨天已經將BlogEngine的可視化編輯器換成了FCKeditor,作為一個程序員,在博客中插入代碼是很重要的一塊。網上現有的都是修改FCKeditor的fckeditorcode_gecko.js和fckeditorcode_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文件中插入下面的代碼: 
//插入代碼 
復制代碼代碼如下:

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); 



在FCKeditor/editor/plugins/insertcode目錄下創建images,lang,languages目錄,在lang目錄下新建en.js,zh-cn.js。en.js的內容為: 
FCKLang.InsertCode = 'Insert Codes' ; 
zh-cn.js的內容為: 
FCKLang.InsertCode = '插入代碼' ; 
下載CodeHighlighter
控件并解壓,把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/editor/plugins/insertcode/images/insertcode.gif。 

在FCKeditor/editor/plugins/insertcode/目錄下新建insertcode.aspx,注意,如果是用Visual Studio新建的話
asp.net 為FCKeditor開發代碼高亮插件實現代碼
insertcode.aspx內容如下: 
復制代碼代碼如下:

<%@ 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> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<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("代碼內容不能為空!"); 
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> 
</head> 
<body> 
<form id="form1" runat="server"> 
<div> 
<div class="langType"> 
語言類型:<asp:DropDownList ID="ddlLangType" runat="server"> 
</asp:DropDownList> 
<asp:CheckBox ID="chkOutLining" Text="折疊代碼" runat="server" Checked="true" /> 
<asp:CheckBox ID="chkLineNum" Text="允許行號" 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=" 轉 換 " 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> 
</html>



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

最后修改Web.config文件:(請參考CodeHighlighter/Web.config) 
在<configuration>里插入: 
<configSections> 
<section name="codeHighlighter" requirePermission="false" type="ActiproSoftware.CodeHighlighter.CodeHighlighterConfigurationSectionHandler, ActiproSoftware.CodeHighlighter.Net20" /> 
</configSections> 




在<system.web></system.web>后插入: 
<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> 


這次的插件就完工了。這種方法可以說是一勞永逸,以后更換高版本的FCKeditor時,只需要修改fckconfig.js將這個插件加入就可以了


注:相關教程知識閱讀請移步到編輯器頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 免费黄色短视频网站 | 国产精品久久久久久久四虎电影 | 黄视频网址 | 国产1区2区3区在线观看 | www69xxxxx| 乱淫67194| 海角在线观看91一区二区 | 国产精品久久久久久久久久 | asiass极品裸体女pics | 国产99精品在线 | www国产成人免费观看视频,深夜成人网 | 国产三级a三级三级 | 96视频在线免费观看 | 国产精品久久久久久影院8一贰佰 | 羞羞的网址 | 韩国一级免费视频 | 老子午夜影院 | 在线观看免费污视频 | 成人男女啪啪免费观看网站四虎 | 日本中文字幕久久 | 香蕉久久久 | 一本色道久久99精品综合蜜臀 | chinese-xvideos| 美女黄网站免费观看 | 欧美成人精品一区二区三区 | 91重口视频 | av在线在线 | 日本教室三级在线看 | 国产欧美日韩在线不卡第一页 | 欧美成人免费tv在线播放 | 日本精品中文字幕 | 天天操天天碰 | 欧美色大成网站www永久男同 | 国产精品999在线观看 | 最污网站 | 精品亚洲综合 | 亚洲免费视频大全 | 精品一区二区免费 | 韩国草草影院 | 粉嫩粉嫩一区二区三区在线播放 | av观看网站 |