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

DedeCms 5.7 代碼高亮實(shí)現(xiàn)方法

  發(fā)布時(shí)間:2012-03-30 00:02:59   作者:佚名   我要評(píng)論
織夢(mèng)CMS是國(guó)內(nèi)比較優(yōu)秀的CMS建站系統(tǒng)之一,DedeCms采用CKEditor在線編輯器,本文講一下DedeCms 5.7在CKEditor中如何實(shí)現(xiàn)代碼高亮
無論建博客網(wǎng)站還是CMS類型網(wǎng)站,很多都需要代碼高亮,織夢(mèng)CMS是國(guó)內(nèi)比較優(yōu)秀的CMS建站系統(tǒng)之一,不像Wordpress一樣有大把大把的插件可用,我用的是最新的dedeCMS 5.7,在網(wǎng)上搜了很長(zhǎng)時(shí)間資料,大都寫的是CKEditor和SyntaxHighlighter整合的文章,但是dedecms將ckeditor做了集成,和一般的只針對(duì)于ckeditor對(duì)config.js修改不同。所以只能自己琢磨修改了,現(xiàn)將方法寫出供站長(zhǎng)朋友們參考:
一、首先去SyntaxHighlighter官方網(wǎng)站下載,網(wǎng)址:http://alexgorbatchev.com/SyntaxHighlighter/download/,建議下載2.1版本,3.0版本的貌似不支持自動(dòng)換行,這里使用的是2.1.382版本。將下載的文件解壓在syntaxHighlight文件夾里,去除里面無用的文件,只留下scripts和styles文件夾。
二、新建dialogs文件夾,在里面新建一個(gè)名為syntaxhighlight.js的文件,因代碼量過大,不宜貼出,請(qǐng)直接下載syntaxhighlight.js
如果想修改代碼區(qū)域的樣式請(qǐng)?jiān)谝韵麓a處修改<table>標(biāo)簽里的樣式。

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

onOk : function() {
var i = this.getParentEditor();
var h = i.getSelection();
var g = h.getStartElement();
var l = g && g.getAscendant("pre", true);
var j = f();
this.commitContent(j);
var k = e(j);
var m = CKEDITOR.dom.element
.createFromHtml('<table style="border:1px solid #EAED9C;width:660px;"><tr><td><pre class="' + k + '">'
+ c(j.code) +"</pre></td></tr><table>");
if (l) {
m.insertBefore(l);
l.remove()
} else {
i.insertElement(m)
}
},

三、然后新建images文件夾,存放一個(gè)syntaxhighlight.gif圖片文件,該圖片文件在編輯器工具欄上顯示,可以使用16*16像素的圖片
四、新建lang文件夾,是語言包,里面有兩個(gè)文件,一個(gè)是中文cn.js一個(gè)是英文en.js,代碼內(nèi)容如下:
 en.js代碼如下:

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

CKEDITOR.plugins.setLang('syntaxhighlight', 'en',
{
syntaxhighlight:
{
title: 'Add or update a code snippet',
sourceTab: 'Source code',
langLbl: 'Select language',
advancedTab: 'Advanced',
hideGutter: 'Hide gutter',
hideGutterLbl: 'Hide gutter & line numbers.',
hideControls: 'Hide controls',
hideControlsLbl: 'Hide code controls at the top of the code block.',
collapse: 'Collapse',
collapseLbl: 'Collapse the code block by default. (controls need to be turned on)',
showColumns: 'Show columns',
showColumnsLbl: 'Show row columns in the first line.',
lineWrap: 'Disable line wrapping',
lineWrapLbl: 'Switch off line wrapping.',
lineCount: 'Default line count',
highlight: 'Highlight lines',
highlightLbl: 'Enter a comma seperated lines of lines you want to highlight, eg <em>3,10,15</em>.'
}
});

cn.js代碼如下:

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

CKEDITOR.plugins.setLang('syntaxhighlight', 'cn',
{
syntaxhighlight:
{
title: '添加或更新代碼',
sourceTab: '代碼',
langLbl: '選擇語言',
advancedTab: '高級(jí)',
hideGutter: '隱藏分割線',
hideGutterLbl: '隱藏分割線和行號(hào)',
hideControls: '隱藏工具欄',
hideControlsLbl: '隱藏浮動(dòng)工具欄',
collapse: '代碼折疊',
collapseLbl: '默認(rèn)折疊代碼塊 (需要啟用工具欄)',
lineWrap: '自動(dòng)換行',
lineWrapLbl: '關(guān)閉自動(dòng)換行',
autoLinks: '自動(dòng)鏈接',
autoLinksLbl: '不自動(dòng)轉(zhuǎn)換超鏈接',
lineCount: '起始行號(hào)',
highlight: '高亮行號(hào)',
highlightLbl: '輸入以逗號(hào)分隔的行號(hào), 如 <em>3,10,15</em>.'
}
});

五、新建plugin.js文件,該文件是ckeditor插件必須得文件,里面是對(duì)該插件的一些配置,代碼如下:

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

CKEDITOR.plugins.add("syntaxhighlight", {
requires : [ "dialog" ],
lang : [ "cn" ],
init : function(a) {
var b = "syntaxhighlight";
var c = a.addCommand(b, new CKEDITOR.dialogCommand(b));
c.modes = {
wysiwyg : 1,
source : 1
};
c.canUndo = false;
a.ui.addButton("Code", {
label : a.lang.syntaxhighlight.title,
command : b,
icon : this.path + "images/syntaxhighlight.gif"
});
CKEDITOR.dialog.add(b, this.path + "dialogs/syntaxhighlight.js")
}
});

六、由于dedecms 5.7自己集成了一個(gè)dedepage插件,用來添加ckeditor自定義插件,在/include/ckeditor/dedepage文件夾下,打開plugin.js文件在最后面添加:
requires : ['syntaxhighlight'],其中syntaxhighlight為代碼高亮插件的文件夾名,添加完之后的代碼如下:
[code]
// Register a plugin named "dedepage".
(function()
{
CKEDITOR.plugins.add( 'dedepage',
{
init : function( editor )
{
// Register the command.
editor.addCommand( 'dedepage',{
exec : function( editor )
{
// Create the element that represents a print break.
// alert('dedepageCmd!');
editor.insertHtml("

相關(guān)文章

最新評(píng)論