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

首頁(yè) > 網(wǎng)站 > 軟件應(yīng)用 > 正文

ckeditor syntaxhighlighter代碼高亮插件配置分享

2024-09-06 19:17:01
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

最近由于自己想做一個(gè)網(wǎng)站形式的代碼庫(kù),自已寫一個(gè)在線文本編輯器,對(duì)于現(xiàn)在的我來(lái),確實(shí)是很不切實(shí)際,呵呵!再說(shuō)了,現(xiàn)在有一個(gè)非常好的在線文本編輯器(ckeditor)了,我和必再去費(fèi)這等功夫呢!有現(xiàn)成的,拿過(guò)用就是的唄!正所謂的拿來(lái)主義!不過(guò)這個(gè)在線文本編輯器,對(duì)于我們程序員來(lái)說(shuō)有一個(gè)算是缺陷吧!沒有代碼高亮的功能!這樣把代碼貼上去,很不好看!今天晚上,我總是把他給弄出來(lái)了。當(dāng)然也采在別人的肩膀上做成的。在此感謝他們的分享!費(fèi)話不多說(shuō)了!咱們進(jìn)入正題吧!

首先去官方網(wǎng)站下載個(gè)ckeditor

其次去官方網(wǎng)站下載個(gè)syntaxhighlighter ,這個(gè)是代碼高亮插件。

還有就是請(qǐng)把我下面提供下載的Demo里的syntaxhighlighter/shBrushes.js文件

下載以后,把他們解壓,加入項(xiàng)目,如下所示:

然后在ckeditor下面新建一個(gè)文件夾,命名為:insertcode,然后在"insertcode"目錄下新建一個(gè)"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');  }});

目錄結(jié)構(gòu)如下圖:圖二

再新建一個(gè)images文件夾,放入一個(gè)"code.jpg"的圖片,如上圖所示,當(dāng)然圖片可以從google找一個(gè),16*16大小的就好了。

再新建一個(gè)dialogs文件夾,新建一個(gè)"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 () {    }  };});

接下來(lái),我們就把高亮插件插入到ckeditor里來(lái),找到ckeditor文件夾下的"ckeditor.js"。按ctrl+F查找"about",找到"fullPage:false,height:200,plugins:'about,basicstyles",我們?cè)?about"后面增加",insertcode",這里就變成"plugins:'about,insertcode,basicstyles"。

如圖:

 繼續(xù)查找"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');}});",我們?cè)谶@個(gè)分號(hào)后面增加"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');}});"。

 如下圖:

 接下來(lái)繼續(xù)在ckeditor.js查找"i.toolbar_Basic=",這就是CKEditor默認(rèn)的工具欄了,我們?cè)谶@里加上",insertcode",比如我的"['Maximize','ShowBlocks','-','insertcode']"

我添加在如下圖選中的文本那個(gè)地方:

最后一步:進(jìn)入"ckeditor/lang",請(qǐng)注意是分別在"en.js","zh.js","zh-cn.js"中增加",insertcode:'Insert Code'",",insertcode:'插入代

主站蜘蛛池模板: 肃宁县| 海兴县| 武威市| 梁山县| 泗洪县| 钦州市| 金平| 独山县| 阜城县| 库尔勒市| 酒泉市| 理塘县| 桂平市| 资溪县| 西峡县| 荥经县| 玉林市| 清丰县| 柯坪县| 杭锦旗| 山东| 南溪县| 林西县| 丰宁| 新田县| 财经| 台东市| 巴彦县| 汉阴县| 呼图壁县| 云安县| 新乐市| 岳普湖县| 盐源县| 高密市| 马山县| 古丈县| 绵阳市| 通渭县| 比如县| 淳化县|