ckeditor syntaxhighlighter代碼高亮插件配置分享
最近由于自己想做一個(gè)網(wǎng)站形式的代碼庫(kù),自已寫一個(gè)在線文本編輯器,對(duì)于現(xiàn)在的我來,確實(shí)是很不切實(shí)際,呵呵!再說了,現(xiàn)在有一個(gè)非常好的在線文本編輯器(ckeditor)了,我和必再去費(fèi)這等功夫呢!有現(xiàn)成的,拿過用就是的唄!正所謂的拿來主義!不過這個(gè)在線文本編輯器,對(duì)于我們程序員來說有一個(gè)算是缺陷吧!沒有代碼高亮的功能!這樣把代碼貼上去,很不好看!今天晚上,我總是把他給弄出來了。當(dāng)然也采在別人的肩膀上做成的。在此感謝他們的分享!費(fèi)話不多說了!咱們進(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 () {
}
};
});
接下來,我們就把高亮插件插入到ckeditor里來,找到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');}});"。
如下圖:

接下來繼續(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:'插入代碼'",",insertcode:'插入代碼'",一定要按這個(gè)順序加哦。
如下圖是en.js中的,zh-cn.js,zh.js我就不一一截圖了。

最后在頁(yè)面上添加如下引用:
<head runat="server"> <title></title> <link type="text/css" rel="stylesheet" href="syntaxhighlighter_3.0.83/styles/shCore.css" /> <link type="text/css" rel="stylesheet" href="syntaxhighlighter_3.0.83/styles/shThemeDefault.css" /> <script type="text/javascript" src="syntaxhighlighter_3.0.83/scripts/shCore.js"></script> <script type="text/javascript" src="syntaxhighlighter_3.0.83/scripts/shBrushes.js"></script> <script type="text/javascript" src="ckeditor/ckeditor.js"></script> <link type="text/css" rel="Stylesheet" href="syntaxhighlighter_3.0.83/styles/shCoreDefault.css" /> <script type="text/javascript"> SyntaxHighlighter.all();</script> </head>
頁(yè)面的代碼如下:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="txtcontent" runat="server" TextMode="MultiLine" Height="310px"
Width="100%"></asp:TextBox>
<script type="text/javascript">
CKEDITOR.replace('<%= txtcontent.ClientID %>', { skin: 'office2003' });
</script>
</script>--%>
<asp:Button runat="server" Text="Button" OnClick="Unnamed1_Click" />
</div>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</form>
后臺(tái)代碼:
protected void Unnamed1_Click(object sender, EventArgs e)
{
this.Literal1.Text = txtcontent.Text;
}
還有就是在頁(yè)面的@ Page指令中加入 ValidateRequest="false",加入后的@Page指令如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false" %>
否則會(huì)報(bào)錯(cuò)的。
效果圖:

怎么獲取這個(gè)文本編輯器里的文本今天白天再寫吧!該睡覺了,1點(diǎn)多了,O My god!
(O YE!現(xiàn)在總是很完善了的)
我的Demo下載:Cheditor+syntaxhighlighter Demo ,如果還有點(diǎn)不懂,請(qǐng)多多參考這個(gè)Demo,或者給我留言吧!
參考博文:http://zhidao.baidu.com/question/302527067.html
http://blog.sina.com.cn/s/blog_5fdcf5c90100uo4r.html
http://www.dbjr.com.cn/article/58407.htm
- SyntaxHighlighter 去掉右側(cè)滾動(dòng)條的方法
- 防止SyntaxHighlighter.js的代碼高亮?xí)r閃一下的解決方法
- SyntaxHighlighter自動(dòng)識(shí)別并加載腳本語(yǔ)言
- z-blog SyntaxHighlighter 長(zhǎng)代碼無法換行解決辦法(基于jquery)
- SyntaxHighlighter 3.0.83使用筆記
- CKEditor中加入syntaxhighlighter代碼高亮插件
- z-blog SyntaxHighlighter 長(zhǎng)代碼無法換行解決辦法(jquery)
- 解決SyntaxHighlighter 代碼高亮不換行問題的解決方法
- FCKeditor + SyntaxHighlighter 讓代碼高亮著色插件
- 代碼著色之SyntaxHighlighter項(xiàng)目(最流行的代碼高亮)
- syntaxhighlighter 去掉右上角問號(hào)圖標(biāo)的三種方法
- 為SyntaxHighlighter添加新語(yǔ)言的方法
- SyntaxHighlighter配合CKEditor插件輕松打造代碼語(yǔ)法著色
- SyntaxHighlighter語(yǔ)法高亮插件使用說明
- ckeditor syntaxhighlighter代碼高亮插件,完美修復(fù)
- coolcode轉(zhuǎn)SyntaxHighlighter與Mysql正則表達(dá)式實(shí)現(xiàn)分析
- FCKeditor 和 SyntaxHighlighter 代碼高亮插件的整合
- SyntaxHighlighter 語(yǔ)法高亮插件的使用教程
- 使用SyntaxHighlighter實(shí)現(xiàn)HTML高亮顯示代碼的方法
- FCKEditor SyntaxHighlighter整合實(shí)現(xiàn)代碼高亮顯示
- SyntaxHighlighter代碼加色使用方法
- syntaxhighlighter 使用方法
- 關(guān)于實(shí)現(xiàn)代碼語(yǔ)法標(biāo)亮 dp.SyntaxHighlighter
- SyntaxHighlighter?Autoloader(自動(dòng)加載)最優(yōu)方式
相關(guān)文章
SyntaxHighlighter配合CKEditor插件輕松打造代碼語(yǔ)法著色
作為程序員在寫博客文章的時(shí)候,經(jīng)常要插入些代碼片斷,很多博客系統(tǒng)都提供代碼語(yǔ)法著色高亮顯示的功能或插件,讓代碼顯示更直接明了2012-09-09
ie9后瀏覽器fckeditor無法上傳圖片、彈出浮層內(nèi)容不顯示的解決方法
升級(jí)到IE9后,fckeditor在IE9里的彈出浮動(dòng)層會(huì)出現(xiàn)bug,里面的內(nèi)容不會(huì)出現(xiàn)。原因是IE9不支持var $=document.getElementById;這樣的寫法了2014-01-01
DISCUZ論壇的UBB編輯器(增加靈活調(diào)用,支持ASP UBB解析)打包下載
從Discuz分離的網(wǎng)頁(yè)編輯器,大家可以加到自己的頁(yè)面上2008-04-04
PHP中CKEditor和CKFinder配置問題小結(jié)
PHP中CKEditor和CKFinder配置問題小結(jié),使用CKEditor和CKFinder編輯器的朋友可以參考下2012-03-03
在kindEditor中獲取當(dāng)前光標(biāo)的位置索引的實(shí)現(xiàn)代碼
一直在用KindEditor,今天要用到光標(biāo)的位置,然后就gg一下辦法,后來發(fā)現(xiàn)這東西的編輯區(qū)域居然是iframe里面的一個(gè)body,不是textarea/input,后來就翻開了他的代碼看,發(fā)現(xiàn)有個(gè)insertHtml2011-11-11
autogrow 讓FCKeditor高度隨內(nèi)容增加的插件
讓FCKeditor高度隨內(nèi)容增加的插件,這個(gè)插件在默認(rèn)情況下可能運(yùn)行不正常,必須做一點(diǎn)修改才可以。2011-02-02
新浪博客在線編輯器傻瓜調(diào)用版(2007.11.1第四次修正)提供下載了
新浪博客在線編輯器傻瓜調(diào)用版(2007.11.1第四次修正)提供下載了...2007-11-11

