欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2009年06月19日 23:59:59   投稿:mdxy-dxy  
近日做個小網(wǎng)站,用到了代碼高亮嵌入顯示功能,想將FCKeditor和dp.SyntaxHighlighter結合使用。

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

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

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

復制代碼 代碼如下:

FCKLang.CodeBtn = '插入高亮代碼' ;
FCKLang.CodeArea = '代碼';
FCKLang.CodeDlgTitle = '插入高亮代碼' ;
FCKLang.CodeDlgName = '語言' ;
FCKLang.CodeErrNoName = '請輸入代碼' ;


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

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

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

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

<!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"); //火狐下提示這里出錯
        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 不明白為什么這三種語言的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;i<codeTypeNum;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">

最終目錄結構如下:

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

復制代碼 代碼如下:

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

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

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

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

最終效果如圖:

相關文章

  • 最新版CKEditor的配置方法及插件(Plugin)編寫示例

    最新版CKEditor的配置方法及插件(Plugin)編寫示例

    本文記錄配置CKEditor過程,并以文章分頁插件為例,簡要CKEditor Plugin編寫過程。 從官網(wǎng)http://ckeditor.com/download下載最新版CKEditor,解壓
    2017-03-03
  • 解決SyntaxHighlighter 代碼高亮不換行問題的解決方法

    解決SyntaxHighlighter 代碼高亮不換行問題的解決方法

    用SyntaxHighlighter 語法高亮插件的朋友可能都遇到過代碼顯示不換行的問題,這個問題在網(wǎng)上也找不到什么解決辦法,一直困擾了我很久,今天算是把它解決了,辦法其實簡單,下面說下如何解決
    2014-11-11
  • CKeditor與syntaxhighlight打造joomla代碼高亮

    CKeditor與syntaxhighlight打造joomla代碼高亮

    最近在用csdn和cnblogs發(fā)帖子和寫隨筆的時候,發(fā)現(xiàn)了好多的IT的網(wǎng)站或者和代碼有關系的一些論壇,博客之類,他們都有一個非常好的語法高亮!很強大!
    2010-07-07
  • 配置fckeditor 實現(xiàn)圖片的上傳

    配置fckeditor 實現(xiàn)圖片的上傳

    配置fckeditor 實現(xiàn)圖片的上傳
    2009-11-11
  • CKEditor中加入syntaxhighlighter代碼高亮插件

    CKEditor中加入syntaxhighlighter代碼高亮插件

    CKEditor是新一代的FCKeditor,是一個重新開發(fā)的版本。CKEditor是全球最優(yōu)秀的網(wǎng)頁在線文字編輯器之一,因其驚人的性能與可擴展性而廣泛的被運用于各大網(wǎng)站
    2014-12-12
  • 使用Js獲取、插入和更改FCKeditor編輯器里的內容

    使用Js獲取、插入和更改FCKeditor編輯器里的內容

    這篇文章主要介紹了使用Js獲取、插入和更改FCKeditor編輯器里的內容,包括JS操作Fckeditor的一些常用方法,需要的朋友可以參考下
    2020-02-02
  • js獲取UEditor富文本編輯器中的圖片地址

    js獲取UEditor富文本編輯器中的圖片地址

    這篇文章主要介紹了js獲取UEditor富文本編輯器中的圖片地址,最簡單的思路應該是先獲取UEditor中的內容再將獲取到的字符串轉換成jquery對象,選擇器找到img元素,獲取src值
    2020-02-02
  • HTML 編輯器 FCKeditor使用詳解

    HTML 編輯器 FCKeditor使用詳解

    最近使用fckeditor的人是越來越多了,隨著大家環(huán)境的不一樣也導致大家在使用過程中碰到了各種各樣的問題,這篇文章對于細節(jié)的描述不錯,更高級的技巧可以參考腳本之家之前發(fā)布的一些文章。
    2009-06-06
  • FCKeditor smarty 編輯器的應用PHP

    FCKeditor smarty 編輯器的應用PHP

    自己仔細研究一下很容易解決你這個問題的。這并不是一個很困難的任務。其實這里很多都是菜鳥級別的
    2012-07-07
  • nicedit 輕量級編輯器 使用心得

    nicedit 輕量級編輯器 使用心得

    NicEdit是一個輕量級,跨平臺,內置內容編輯器,允許在瀏覽器中輕松地編輯網(wǎng)站上的內容。
    2009-06-06

最新評論