最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

asp.net 為FCKeditor開發(fā)代碼高亮插件實現(xiàn)代碼

 更新時間:2008年08月15日 19:38:07   作者:  
昨天已經(jīng)將BlogEngine的可視化編輯器換成了FCKeditor,作為一個程序員,在博客中插入代碼是很重要的一塊。網(wǎng)上現(xiàn)有的都是修改FCKeditor的fckeditorcode_gecko.js和fckeditorcode_ie.js以達到InsertCode的目的。這個方法非常麻煩,當(dāng)要使用FCKeditor新版本時都要重新修改這兩個文件,非常影響我們的效率。
所以就為FCKeditor寫了個InsertCode的插件。整個插件的制作過程非常簡單:
FCKeditor插件開發(fā)請參考FCKeditor官網(wǎng)的文檔:

http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Customization/Plug-ins
首先,我們在FCKeditor/editor/plugins目錄下新建一個insertcode目錄,并在insertcode目錄下新建一個fckplugin.js文件。
在新建的fckplugin.js文件中插入下面的代碼:
//插入代碼
復(fù)制代碼 代碼如下:

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目錄下創(chuàng)建images,lang,languages目錄,在lang目錄下新建en.js,zh-cn.js。en.js的內(nèi)容為:
FCKLang.InsertCode = 'Insert Codes' ;
zh-cn.js的內(nèi)容為:
FCKLang.InsertCode = '插入代碼' ;
下載CodeHighlighter http://m.fzitv.net/codes/94.html
控件并解壓,把CodeHighlighter/bin目錄下的ActiproSoftware.CodeHighlighter.Net20.dll,ActiproSoftware.Shared.Net20.dll,CodeHighlighterTest.dll三個DLL復(fù)制到BlogEngine.Web/bin目錄,
將CodeHighlighter/Languages里的Lexers整個目錄復(fù)制到FCKeditor/editor/plugins/insertcode/languages目錄,
將CodeHighlighter/Images/OutliningIndicators/目錄下的所有圖片復(fù)制到FCKeditor/editor/plugins/insertcode/images目錄,并將這個圖片下載保存到FCKeditor/editor/plugins/insertcode/images/insertcode.gif。

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

insertcode.aspx內(nèi)容如下: 
復(fù)制代碼 代碼如下:

<%@ 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(" ", "&nbsp;&nbsp;").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("代碼內(nèi)容不能為空!");
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=" 轉(zhuǎn) 換 " 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將這個插件加入就可以了

相關(guān)文章

  • ASX文件 終極教程

    ASX文件 終極教程

    整理資料的時候,發(fā)現(xiàn)電腦里保存了一些ASX文件。這些文件原來是玩MSN空間時用到的,主要用于在MSN空間上安裝播放器。很久沒玩MSN空間了,雖然現(xiàn)在也還在用MSN,但MSN空間的速度真的是慢得讓我難以接受,所以還是不用MSN空間。順便分析一下ASX文件的格式,以方便那些還在用MSN空間的朋友。
    2008-02-02
  • FCKEDITOR 相關(guān)函數(shù)介紹

    FCKEDITOR 相關(guān)函數(shù)介紹

    FCKeditorAPI是FCKeditor加載后注冊的一個全局對象,利用它我們就可以完成對編輯器的各種操作。
    2010-07-07
  • FCKEditor 自定義用戶目錄的修改步驟 (附源碼)

    FCKEditor 自定義用戶目錄的修改步驟 (附源碼)

    FCKEditor 自定義用戶目錄的修改步驟 (附源碼) ,需要的朋友可以參考下。
    2010-03-03
  • 百度編輯器二次開發(fā)常用手記整理小結(jié)

    百度編輯器二次開發(fā)常用手記整理小結(jié)

    最近一直在做百度編輯器的二次開發(fā),忙乎了一段時間,今天把一些常用的資料,整理出來,供以后查詢
    2012-07-07
  • 19款Javascript富文本網(wǎng)頁編輯器

    19款Javascript富文本網(wǎng)頁編輯器

    19款javascript富文本編輯器。也許你還有興趣查看15個基于Web的HTML編輯器和6款所見即所得(WYSIWYG)的在線Web編輯器。
    2010-11-11
  • ckeditor插件開發(fā)簡單實例

    ckeditor插件開發(fā)簡單實例

    我需要在編輯文本的時候,選擇一段文字,點擊自定義的按鈕,就能夠在這段文字后面增加一個圖標,圖標超鏈接去一個地址,以選中的文字作為參數(shù)
    2013-07-07
  • FCKeditor提供了一個完整的JavaScript API

    FCKeditor提供了一個完整的JavaScript API

    FCKeditor提供了一個完整的JavaScript API(Application Public Interface),你可以利用這些API來處理FCK編輯器,只要它被加載完成或在正在運行中.
    2009-12-12
  • FckEditor 配置手冊中文教程詳細說明

    FckEditor 配置手冊中文教程詳細說明

    首先,FCKEDITOR的性能是非常好的,用戶只需很少的時間就可以載入 FCKEDITOR所需文件.對于其他在線編輯器來說,這幾乎是個很難解決的難題,因為在開啟編輯器時需要裝載太多的文件.
    2009-04-04
  • kindSoft在線網(wǎng)頁編輯器簡單的配置參數(shù)介紹

    kindSoft在線網(wǎng)頁編輯器簡單的配置參數(shù)介紹

    對于網(wǎng)頁編輯器對做項目的時候是非常的又用的一個編輯器,大大的減輕了開發(fā)人員的負擔(dān),感覺KindSoft是一個不錯的選擇,因此也在不斷的使用接下來介紹參數(shù)配置,需要的朋友可以了解下
    2013-01-01
  • Ewebeditor及fckeditork單引號問題的解決方法

    Ewebeditor及fckeditork單引號問題的解決方法

    為什么一個簡單的單引號會引發(fā)不能添加到數(shù)據(jù)庫呢,想到這里,我們想到了分析下入庫代碼并找出了原因,下面是解決方法。
    2010-04-04

最新評論

江都市| 嵊州市| 英德市| 山西省| 武隆县| 河东区| 措勤县| 沾益县| 方城县| 唐山市| 中方县| 灵寿县| 和静县| 肃宁县| 齐河县| 班戈县| 仪征市| 茌平县| 黄龙县| 西丰县| 广饶县| 腾冲县| 邯郸县| 吉林市| 汝阳县| 水富县| 皮山县| 临泉县| 遵义市| 林周县| 景洪市| 吉木乃县| 郎溪县| 阳西县| 吴堡县| 岚皋县| 馆陶县| 西盟| 鄢陵县| 宁津县| 宁阳县|