国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > 軟件應用 > 正文

CKEditor中加入syntaxhighlighter代碼高亮插件

2024-09-06 19:17:00
字體:
來源:轉載
供稿:網友

從官網 下載ckeditor,我下載的是CKEditor 3.3.1 。CKEditor與原來的FCKeditor有太大的不同了,作為開發人員,在做自己的博客的時候總是需要貼代碼的,只好給它先做一個插入代碼的插件了。高亮代碼用的是"SyntaxHighlighter "。

1、在"ckeditor/plugins/"目錄下新建一個"insertcode"目錄,然后在"insertcode"目錄下新建一個"plugin.js",輸入以下代碼:

CKEDITOR.plugins.add('insertcode', {requires: ['dialog'], init: function(a){var b = a.addCommand('insertcode', new CKEDITOR.dialogCommand('insertcode'));a.ui.addButton('insertcode', {label: a.lang.insertcode.toolbar, command: 'insertcode',icon: this.path + 'images/code.jpg'});CKEDITOR.dialog.add('insertcode', this.path + 'dialogs/insertcode.js'); }});

2、增加"images"目錄,放入一個"code.jpg"的圖片(附件中上傳了一個code的jpg圖片,大家可以直接使用)。

3、增加"dialogs"目錄,新建一個"insertcode.js",輸入如下代碼:

CKEDITOR.dialog.add('insertcode', function(editor){  var escape = function(value){   return value;  };  return {   title: 'Insert Code Dialog',   resizable: CKEDITOR.DIALOG_RESIZE_BOTH,   minWidth: 720,   minHeight: 480,   contents: [{    id: 'cb',    name: 'cb',    label: 'cb',    title: 'cb',    elements: [{     type: 'select',     label: 'Language',     id: 'lang',     required: true,     'default': 'csharp',     items: [['ActionScript3', 'as3'], ['Bash/shell', 'bash'], ['C#', 'csharp'], ['C++', 'cpp'], ['CSS', 'css'], ['Delphi', 'delphi'], ['Diff', 'diff'], ['Groovy', 'groovy'], ['Html', 'xhtml'], ['JavaScript', 'js'], ['Java', 'java'], ['JavaFX', 'jfx'], ['Perl', 'perl'], ['PHP', 'php'], ['Plain Text', 'plain'], ['PowerShell', 'ps'], ['Python', 'py'], ['Ruby', 'rails'], ['Scala', 'scala'], ['SQL', 'sql'], ['Visual Basic', 'vb'], ['XML', 'xml']]    }, {     type: 'textarea',     style: 'width:700px;height:420px',     label: 'Code',     id: 'code',     rows: 31,     'default': ''    }]   }],   onOk: function(){    code = this.getValueOf('cb', 'code');    lang = this.getValueOf('cb', 'lang');    html = '' + escape(code) + '';    editor.insertHtml("<pre class=/"brush:" + lang + ";/">" + html + "</pre>");   },   onLoad: function(){   }  }; }); 

 我是用"syntaxhighlighter"來做代碼高亮的,如果你不喜歡它也可以換成其它的。 

4、接下來就是把插件加入到CKEditor里了,我是直接修改CKEditor插件的核心文件的,因為我是把“插入代碼”功能做為一個編輯器必要的功能來使用的。

     找到ckeditor目錄下的"ckeditor.js",這里的代碼是經過壓縮的,我們用CKEditor原來的about插件做參考。查找"about",找到"fullPage:false,height:200,plugins:'about,basicstyles ",我們在"about"后面增加",insertcode",這里就變成"plugins:'about,insertcode ,basicstyles"。

    繼續查找"about",找到"j.add('about',{init:function(l){var m=l.addCommand('about',new a.dialogCommand('about'));m.modes={wysiwyg:1,source:1};m.canUndo=false;l.ui.addButton('About',{label:l.lang.about.title,command:'about'});a.dialog.add('about',this.path+'dialogs/about.js');}}); ",我們在這個分號后面增加"j.add('insertcode', {requires: ['dialog'],init: function(l){l.addCommand('insertcode', new a.dialogCommand('insertcode'));l.ui.addButton('insertcode', {label: l.lang.insertcode.toolbar,command: 'insertcode',icon: this.path + 'images/code.jpg'});a.dialog.add('insertcode', this.path + 'dialogs/insertcode.js');}}); "。

    接下來查找"i.toolbar_Basic=",這就是CKEditor默認的工具欄了,我們在這里加上",insertcode ",你可以加在你想要的位置。比如我的"['Maximize','ShowBlocks','-','insertcode'] "。

    5、進入"ckeditor/lang",分別在"en.js","zh.js","zh-cn.js"中增加",insertcode:'Insert Code' ",",insertcode:'插入代

主站蜘蛛池模板: 衡阳县| 达孜县| 平湖市| 平舆县| 吴堡县| 抚顺县| 溧阳市| 腾冲县| 石城县| 永平县| 绥宁县| 洞头县| 长宁区| 柏乡县| 大石桥市| 安陆市| 通许县| 盐城市| 平陆县| 淅川县| 沧州市| 梧州市| 西城区| 利川市| 化隆| 永仁县| 恩施市| 桐柏县| 泰来县| 双鸭山市| 雷山县| 盐津县| 道真| 古蔺县| 独山县| 武威市| 昌图县| 儋州市| 青海省| 密山市| 海淀区|