前军教程网

中小站长与DIV+CSS网页布局开发技术人员的首选CSS学习平台

基于帝国CMS7.5版本编辑器代码高亮设置

因为发的技术文章多半含有代码,如果没有代码插件,那代码就显的太难看了,恰好ckeditor官方提供了高亮插件,这里记录一下如何实现。

一、下载插件及依赖工具

Code Snippet

widget

lineutils

widgetselection

二、将下载的插件解压,并复制到帝国的ckeditor目录下,注意是后台的那个

默认后台目录:e\admin\ecmseditor\infoeditor\plugins

三、修改配置文件

配置文件路径:e\admin\ecmseditor\infoeditor\config.js

配置文件中共有两个工具条,一个是全功能的,一个是精简的

在两个工具条中添加代码工具CodeSnippet

然后在工具条下方添加代码工具的配置

这里我把我的发上来供大家参考

CKEDITOR.editorConfig = function( config ) {
	// Define changes to default configuration here. For example:
	// config.language = 'fr';
	// config.uiColor = '#AADC6E';
	
	config.filebrowserImageUploadUrl = '';
	config.filebrowserFlashUploadUrl = arraycs[0];
	config.filebrowserImageBrowseUrl = arraycs[1];
	config.filebrowserFlashBrowseUrl = arraycs[1];
	
	config.enterMode = CKEDITOR.ENTER_BR;
	config.shiftEnterMode = CKEDITOR.ENTER_P;
	config.allowedContent= true;
	
	config.font_names='宋体/宋体;黑体/黑体;仿宋/仿宋_GB2312;楷体/楷体_GB2312;隶书/隶书;幼圆/幼圆;微软雅黑/微软雅黑;'+ config.font_names;
	
	// Toolbar
	config.toolbar_full = [
	{ name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source', '-', 'Preview', 'Print' ] },
	{ name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
	
	{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl' ] },
	'/',
	{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat', 'ecleanalltext', 'autoformat' ] },
	
	{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
	{ name: 'insert', items: [ 'Image', 'etranmore', 'Flash', 'etranmedia', 'etranfile', '-', 'Table', 'HorizontalRule', 'SpecialChar','CodeSnippet', 'equotetext', 'einserttime', 'einsertpage', 'einsertbr' ] },
	'/',
	{ name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ] },
	{ name: 'colors', items: [ 'TextColor', 'BGColor' ] },
	{ name: 'tools', items: [ 'ShowBlocks', 'NewPage', 'Templates' ] },
	{ name: 'others', items: [ '-' ] },
	{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ], items: [ 'Find', 'Replace', '-', 'SelectAll', 'Maximize' ] }
];
	// Toolbar
	config.toolbar_basic = [
	{ name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source' ] },
	{ name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
	{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
	{ name: 'insert', items: [ 'Image', 'Table', 'HorizontalRule', 'SpecialChar','CodeSnippet' ] },
	{ name: 'tools', items: [ 'Maximize' ] },
	{ name: 'others', items: [ '-' ] },
	'/',
	{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Strike', '-', 'RemoveFormat' ] },
	{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote' ] },
	{ name: 'styles', items: [ 'Styles', 'Format' ] },
];
	config.extraPlugins = 'etranfile,etranmedia,etranmore,autoformat,ecleanalltext,einsertbr,einsertpage,einserttime,equotetext';
	config.extraPlugins ='codesnippet';
	config.codeSnippet_theme = 'monokai_sublime';
	config.toolbar = 'full';
};

做完以上步骤,代码在后台是高亮的,但是在前台还不是高亮显示。现在需要我们做最后一步。

将gaoliang.css以及highlight.pack.js文件上传到网站服务器中,并在内容模板body前添加以下代码。

<link href="[!--news.url--]skin/jxhx/css/highlight.css" rel="stylesheet">
<script src="[!--news.url--]skin/jxhx/js/highlight.pack.js" ></script>
<script>hljs.initHighlightingOnLoad();</script>

其中skin/jxhx/css和skin/jxhx/js是我放置文件的路径,可以随意更改,路径正确就可以。

上述所有的插件可以通过链接跳转下载,css和js文件可以从我网站张扒下来,所有的文件我都进行了打包。

帝国CMS7.5版本编辑器代码高亮设置所有插件以及文件下载,提取码:pspl。

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言