主頁(yè) > 知識(shí)庫(kù) > FCKEditor SyntaxHighlighter整合實(shí)現(xiàn)代碼高亮顯示

FCKEditor SyntaxHighlighter整合實(shí)現(xiàn)代碼高亮顯示

熱門標(biāo)簽:四平電話機(jī)器人哪家好 株洲外呼營(yíng)銷系統(tǒng)有哪些 長(zhǎng)春銷售外呼系統(tǒng)業(yè)務(wù) 長(zhǎng)春防封卡電銷卡套餐 天津電銷卡外呼系統(tǒng)線路 靈聲智能電話機(jī)器人招聘 興化400電話辦理多少錢 智能電銷機(jī)器人真的好嗎 企業(yè)電話機(jī)器人辦理

因此上網(wǎng)查了許多資料,沒有說怎么做的,都是自己改好一個(gè)包上傳。我研究了一個(gè)這些整合好的例子,粗略說一說,對(duì)以后開發(fā)其它FCKeditor插件也有好處。
為方便大家使用,腳本之家特提供兩個(gè)已經(jīng)做成插件的版本。下載地址
第一步:在FCKeditor的路徑中找到“editor\plugins\”,在其中創(chuàng)建“highlighter”文件夾。

第二步:將“dp.SyntaxHighlighter\Scripts”文件夾復(fù)制到此文件夾中,所有的js文件和一個(gè)flash文件也要一通復(fù)制過來。

第三步:在“highlighter\”創(chuàng)建“l(fā)ang”文件夾,在其中新建“zh-cn.js”文件,內(nèi)容如下——

復(fù)制代碼 代碼如下:

FCKLang.CodeBtn = '插入高亮代碼' ;
FCKLang.CodeArea = '代碼';
FCKLang.CodeDlgTitle = '插入高亮代碼' ;
FCKLang.CodeDlgName = '語(yǔ)言' ;
FCKLang.CodeErrNoName = '請(qǐng)輸入代碼' ;


第四步:在“highlighter\”創(chuàng)建“fckplugin.js”,內(nèi)容如下——此文件內(nèi)容也可以參考其他plugins目錄下的同名文件。
復(fù)制代碼 代碼如下:

// Register the related commands.
//FCKCommands.RegisterCommand( 'HighLighter', new FCKDialogCommand("HighLighter",FCKLang.DlgHighLighterTitle,FCKConfig.Plugins.Items['highlighter'].Path + 'highlighter.html', 540, 540 ) ) ;
FCKCommands.RegisterCommand( 'HighLighter', new FCKDialogCommand("HighLighter",FCKLang['CodeDlgTitle'],FCKConfig.PluginsPath + 'highlighter/highlighter.html', 540, 500 ) ) ;
// Create the "highlighter" toolbar button.
var oHighLighterItem        = new FCKToolbarButton( 'HighLighter', FCKLang['CodeBtn'] ) ;
oHighLighterItem.IconPath    = FCKConfig.PluginsPath + 'highlighter/highlighter.gif' ;
FCKToolbarItems.RegisterItem( 'HighLighter', oHighLighterItem );// 'HighLighter' is the name used in the Toolbar config.
var FCKHighLighter = new Object();
var CSS_PATH      = FCKConfig.PluginsPath + "highlighter/dp.SyntaxHighlighter/Styles/";
var pool = {"firstCss" : true };
FCKHighLighter.Add = function( value ){
    var oDiv = FCK.CreateElement("div");
    oDiv._FCKhighLighter = "hlDiv" + Math.random() ;
    oDiv.className="dp-highlighter";
    oDiv.innerHTML = value;
    if(pool.firstCss) {
        pool.firstCss = false;
        //oDiv.innerHTML += "link href="" + CSS_PATH + "SyntaxHighlighter.css" href="" + CSS_PATH + "SyntaxHighlighter.css"" + "type='text/css' rel='stylesheet'>/link>";
    }
    // alert(oDiv.innerHTML);
}
FCKHighLighter.OnDoubleClick = function( div ){
//    if(div._FCKhighLighter = "hlDiv") FCKCommands.GetCommand( 'HighLighter' ).Execute() ;
    if(div.className == "dp-highlighter" div.tagName=="DIV") FCKCommands.GetCommand( 'HighLighter' ).Execute() ;
}
FCK.RegisterDoubleClickHandler( FCKHighLighter.OnDoubleClick, 'DIV' ) ;

第五步:找一個(gè)21×21px的gif圖片作為按鈕,取名為“highlighter.gif”。

第六步:關(guān)鍵步驟,創(chuàng)建插入代碼對(duì)話框,取名為“highlighter.html”。內(nèi)容如下——
復(fù)制代碼 代碼如下:

!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
html xmlns="http://www.w3.org/1999/xhtml">
head>
meta http-equiv="pragma" content="no-cache" />
meta http-equiv="Cache-Control" content="no-cache, must-revalidate" />
meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT" />
meta http-equiv="expires" content="0" />
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shCore.js" src="dp.SyntaxHighlighter/Scripts/shCore.js" >/script>
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shBrushCSharp.js" src="dp.SyntaxHighlighter/Scripts/shBrushCSharp.js">/script>
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shBrushPhp.js" src="dp.SyntaxHighlighter/Scripts/shBrushPhp.js">/script>
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shBrushJScript.js" src="dp.SyntaxHighlighter/Scripts/shBrushJScript.js">/script>
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shBrushJava.js" src="dp.SyntaxHighlighter/Scripts/shBrushJava.js">/script>
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shBrushVb.js" src="dp.SyntaxHighlighter/Scripts/shBrushVb.js">/script>
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shBrushSql.js" src="dp.SyntaxHighlighter/Scripts/shBrushSql.js">/script>
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shBrushXml.js" src="dp.SyntaxHighlighter/Scripts/shBrushXml.js">/script>
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shBrushDelphi.js" src="dp.SyntaxHighlighter/Scripts/shBrushDelphi.js">/script>
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shBrushPython.js" src="dp.SyntaxHighlighter/Scripts/shBrushPython.js">/script>
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shBrushRuby.js" src="dp.SyntaxHighlighter/Scripts/shBrushRuby.js">/script>
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shBrushCss.js" src="dp.SyntaxHighlighter/Scripts/shBrushCss.js">/script>
script type="text/javascript" src="dp.SyntaxHighlighter/Scripts/shBrushCpp.js" src="dp.SyntaxHighlighter/Scripts/shBrushCpp.js">/script>
title>插入代碼/title>
script language="javascript" type="text/javascript">!--
var oEditor = window.parent.InnerDialogLoaded() ;
var FCKLang = oEditor.FCKLang ;
var FCKHighLighter = oEditor.FCKHighLighter ;
window.onload = function () {
    oEditor.FCKLanguageManager.TranslatePage( document ) ;
    window.parent.SetOkButton( true ) ;    
    LoadSelected();
document.getElementById("code").focus();
}
function Ok()
{
    if(document.getElementById("code").value.length==0)
    {
        alert(FCKLang['CodeErrNoName']);
        return false;
    }    
//    dp.SyntaxHighlighter.ClipboardSwf = 'dp.SyntaxHighlighter/Scripts/clipboard.swf';
    var result=dp.SyntaxHighlighter.HighlightAll('code',0,1,0,1,0);
    
    var str = "";
    for(key in result)
    {
        str += result[key][0];
    }
    FCKHighLighter.Add( str ) ;
    return true ;
}
var eSelected = oEditor.FCKSelection.GetSelectedElement() ;
function LoadSelected()
{
    if ( !eSelected ){ return ;}
    if ( eSelected.tagName == 'DIV' eSelected.className=="dp-highlighter" )
    {
     var ol = eSelected.document.getElementsByTagName("ol"); //火狐下提示這里出錯(cuò)
        var codeClass = ol[0].className.substring(3,ol[0].className.length);
     var ddlv='';
     switch(codeClass){
     case "cpp":
     document.getElementById("code").className="cpp";
     ddlv="cpp";
     break;
     case "c": //c#,javascript php 不明白為什么這三種語(yǔ)言的CSS名都是dp-c,所以區(qū)分不了
     document.getElementById("code").className="csharp";
     ddlv="c#";
     break;
     case "css":
     document.getElementById("code").className="css";
     ddlv="css";
     break;
     case "delphi":
     document.getElementById("code").className="delphi";
     ddlv="delphi";
     break;
     case "j":
     document.getElementById("code").className="java";
     ddlv="java";
     break;
     case "py":
     document.getElementById("code").className="python";
     ddlv="python";
     break;
     case "rb":
     document.getElementById("code").className="ruby";
     ddlv="ruby";
     break;
     case "sql":
     document.getElementById("code").className="sql";
     ddlv="sql";
     break;
     case "vb":
     document.getElementById("code").className="vb";
     ddlv="vb";
     break;
     case "xml":
     document.getElementById("code").className="xml";
     ddlv="xml";
     break;
     }
        var codeTypeNum = document.getElementById("codeType").options.length;
        for(var i=0;icodeTypeNum;i++)
        {
            if(document.getElementById("codeType").options[i].value == ddlv)
            {
                document.getElementById("codeType").options[i].selected = true;
            }
        }
//        var codeContent = eSelected.nextSibling.innerHTML;
    //    document.getElementById('code').value = codeContent.replace("lt;" , "");
    //document.getElementById('code').value = codeContent.replace(/[^>]+>/g, "");
    
     if(navigator.userAgent.indexOf("MSIE")>0){
     document.getElementById('code').value = ol[0].innerText;
     }else{
     document.getElementById('code').value = ol[0].textContent;
     }
    }
    else eSelected == null ;
}
// -->/script>
/head>
body>
table style="width:100%;">
tr>
td style="width:10%; line-height:25px;">span fckLang="CodeDlgName">/span>/td>
td>
select id="codeType" style="width:250px;" onchange="document.getElementById('code').className =this.value;">
     option value="csharp">C#/option>
     option value="php">PHP/option>
     option value="javascript">Javascript/option>
     option value="xml">Xml/option>
     option value="xml">Html/option>
     option value="css">Css/option>
     option value="cpp">C/C++/option>
     option value="delphi">Delphi/option>
     option value="java">Java/option>
     option value="python">Python/option>
     option value="ruby">Ruby/option>
     option value="sql">Sql/option>
     option value="vb">VB/option>
     /select>    
/td>
/tr>
tr>
td>span fckLang="CodeArea">/span>/td>
td>
textarea rows="25" cols="80" class="csharp" name="code" id="code">

最終目錄結(jié)構(gòu)如下:

      第七步:找到“fckconfig.js”文件。(這是fckeditor的核心配置文件,應(yīng)該能找到的吧……)找“FCKConfig.ToolbarSets”這個(gè)key,然后在里面加入“'HighLighter'”。例如:

復(fù)制代碼 代碼如下:

FCKConfig.ToolbarSets["Basic"] = [
['Style','FontFormat','FontName','FontSize','-','Bold','Italic','-','TextColor','BGColor','-','HighLighter']

第八步:還是在“fckconfig.js”中,找到“FCKConfig.Plugins”這個(gè)key,添加如下代碼:
復(fù)制代碼 代碼如下:

FCKConfig.Plugins.Add( 'highlighter','zh-cn') ;

好了,以FCKEditor插件形式出現(xiàn)的SyntaxHighlighter代碼高亮顯示就完成了。

最終效果如圖:

您可能感興趣的文章:
  • asp.net 為FCKeditor開發(fā)代碼高亮插件實(shí)現(xiàn)代碼
  • ckeditor syntaxhighlighter代碼高亮插件,完美修復(fù)
  • CKeditor與syntaxhighlight打造joomla代碼高亮
  • CKEditor中加入syntaxhighlighter代碼高亮插件
  • ckeditor syntaxhighlighter代碼高亮插件配置分享
  • FCKeditor 和 SyntaxHighlighter 代碼高亮插件的整合
  • FCKeditor + SyntaxHighlighter 讓代碼高亮著色插件
  • CKeditor富文本編輯器使用技巧之添加自定義插件的方法
  • ckeditor自定義插件使用方法詳解
  • CKEditor 附插入代碼的插件
  • CKEditor 4.4.1 添加代碼高亮顯示插件功能教程【使用官方推薦Code Snippet插件】

標(biāo)簽:貴港 黑龍江 青海 運(yùn)城 石嘴山 巴彥淖爾 漯河 新疆

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《FCKEditor SyntaxHighlighter整合實(shí)現(xiàn)代碼高亮顯示》,本文關(guān)鍵詞  FCKEditor,SyntaxHighlighter,整合,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《FCKEditor SyntaxHighlighter整合實(shí)現(xiàn)代碼高亮顯示》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于FCKEditor SyntaxHighlighter整合實(shí)現(xiàn)代碼高亮顯示的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章