您现在的位置是:首页 > cms教程 > 帝国CMS教程帝国CMS教程
帝国cms编辑器ckeditor安装代码高亮插件
原创2025-09-18帝国CMS教程已有人查阅
导读帝国cms内容文本编辑器多数为ckeditor,官网也提供了很多的扩展功能和插件,但是帝国并没有相关编辑器高亮代码插件,高亮代码就是通过Code Snippet插件来实现高亮代码的功能。我

至于前端显示的风格可以查看这篇文章>>帝国cms高亮代码添加行号前端显示Mac OS风格
安装后的效果

实现步骤
下面是修改的步骤
步骤一:下载codesnippet文件和相关依赖工具
Code Snippet下载地址: https://ckeditor.com/cke4/addon/codesnippet
Widget下载地址: https://ckeditor.com/cke4/addon/widget
Line下载地址: Utilities https://ckeditor.com/cke4/addon/lineutils
将3个文件解压后上传到e/admin/ecmseditor/infoeditor/plugins/
(注意:本人在使用最新版本时并不能实现相关功能,可能是版本不兼容,亦或者是博主技术不到家,如果只是实现相关功能的可以下载博主提供的文件或者下载较老的版本)
步骤二:修改ckeditor配置config.js
修改帝国cms7.5编辑器配置文件e/admin/ecmseditor/infoeditor/config.js
1、增加扩展配置,extraPlugins = 'codesnippet';
大概120行
config.extraPlugins = 'etranfile,etranmedia,etranmore,autoformat,ecleanalltext,einsertbr,einsertpage,einserttime,equotetext';
修改为
config.extraPlugins = 'etranfile,etranmedia,etranmore,autoformat,ecleanalltext,einsertbr,einsertpage,einserttime,equotetext,codesnippet';
2、工具栏添加 CodeSnippet 功能大概在95行'einsertbr'后添加,'CodeSnippet'注意大小写,c和s要大写
{ name: 'insert', items: [ 'Image', 'etranmore', 'Flash', 'etranmedia', 'etranfile', '-', 'Table', 'HorizontalRule', 'SpecialChar', 'equotetext', 'einserttime', 'einsertpage', 'einsertbr','CodeSnippet' ] },
3、设置代码高亮样式在文件末尾添加以下代码
config.codeSnippet_theme= 'monokai_sublime'; //monokai_sublime为高亮css样式文件名
为方便,可直接将下面代码覆盖你的config.js代码
function EcmsEditorDoCKhtml(htmlstr){
if(htmlstr.indexOf('"')!=-1)
{
return '';
}
if(htmlstr.indexOf("'")!=-1)
{
return '';
}
if(htmlstr.indexOf("/")!=-1)
{
return '';
}
if(htmlstr.indexOf("\\")!=-1)
{
return '';
}
if(htmlstr.indexOf("[")!=-1)
{
return '';
}
if(htmlstr.indexOf("]")!=-1)
{
return '';
}
if(htmlstr.indexOf(":")!=-1)
{
return '';
}
if(htmlstr.indexOf("%")!=-1)
{
return '';
}
if(htmlstr.indexOf("<")!=-1)
{
return '';
}
if(htmlstr.indexOf(">")!=-1)
{
return '';
}
return htmlstr;
}
function EcmsEditorGetCs(){
var js=document.getElementsByTagName("script");
for(var i=0;i<js.length;i++)
{
if(js[i].src.indexOf("ckeditor.js")>=0)
{
var arraytemp=new Array();
arraytemp=js[i].src.split('?');
return arraytemp;
}
}
}
var arraycs=new Array();
arraycs=EcmsEditorGetCs();
arraycs[0]=arraycs[0].replace('infoeditor/ckeditor.js','');
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', 'equotetext', 'einserttime', 'einsertpage', 'einsertbr','CodeSnippet' ] },
'/',
{ 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' ] },
{ 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,codesnippet';
config.toolbar = 'full';
config.codeSnippet_theme= 'monokai_sublime'; //monokai_sublime为高亮css样式文件名
};
版本不同替换谨慎,可能需要自己按上面步骤修改。致此ckeditor添加代码高亮功能已经完成了,预览添加效果请清除浏览器缓存。
步骤三:内容页模板添加高亮代码样式
所有的样式都在目录里:e\admin\ecmseditor\infoeditor\plugins\codesnippet\lib\highlight\styles
选择一个自己喜欢的样式,添加到内容模板中,为了不暴露我们的后台登录地址可以把highlight文件复制到根目录的skin文件下
在内容页模板添加以下三行代码,即可高亮显示代码
<link rel="stylesheet" href="[!--news.url--]skin/highlight/styles/monokai_sublime.css">
<script src="[!--news.url--]skin/highlight/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
其他问题的修改1. 代码不能自适应页面大小,或超出部分不显示
修改办法:
在自己引用的css文件中添加以下样式,我引用的是monokai_sublime.css
在css文件中的.hljs{}内添加:
white-space: pre-wrap;
word-break: break-all;//超出部分自动换行
或改为
overflow-y: auto;//当代码超出显示区域将自带滚动条
高亮代码功能修改全部完成。
本文标签:帝国cms功能开发
很赞哦! ()
相关教程
图文教程
帝国CMS多图上传插件安装和使用说明
一、插件介绍:帝国CMS多图上传插件:为采用FLASH方式实现同时选择多个图片一起上传,提高多图上传效率。
帝国CMS按SQL语句查询调用说明教程
按SQL语句查询调用说明1、标签上面的“操作类型”参数要设为24,然后“栏目id”参数为SQL语句2、开启支持按SQL语句调用,默认是开启的,如果没有开启:打开e/class/config.php文件进行配置(粗体文字的设置) //部分参数设置
帝国CMS视频播放器插件参数说明和使用示例
一、显示效果 二、使用语法说明(一)、【显示视频播放器JS函数语法说明】1、格式:参数说明:播放器类型:设为空''或'auto'为自动识别设为'html5video'为采用HTML5的video播放标签
帝国cms数据表phome_enewstempvar公共模板变量表
帝国cms数据表phome_enewstempvar公共模板变量表字段名和解释,方便查询。
相关源码
-
(自适应)居家生活日用品纸盘纸盒纸杯卫生纸巾生产厂家pbootcms模板为纸品生产企业打造的现代化展示平台,自动适应各种设备屏幕,确保浏览体验一致,完善的SEO功能,提升网站曝光度,基于PbootCMS构建,源码开放可定制。查看源码 -
(自适应响应式)环保净化器家用电器网站免费模板针对环保设备、环境监测等领域的PbootCMS响应式模板,通过模块化设计清晰展示污水处理技术、空气净化系统等解决方案。移动端呈现环保数据可视化图表,后端统一管理确保项目案例、技术等资料多端同步。查看源码 -
(自适应)工业机械制造设备网站pbootcms模板下载为机械制造、工业设备类企业设计,特别适合各类机械设备、生产线、工业自动化产品展示。采用响应式技术,确保在不同设备上都能清晰展示机械产品的技术参数和细节特点。查看源码 -
帝国CMS7.5手游资讯下载综合门户免费网站模板本模板基于帝国CMS7.5内核开发,为手游打造的综合门户网站解决方案。模板设计充分考虑了手业的特性,包含游戏资讯发布、手游下载、礼包发放、开测信息等核心功能模块,满足手游门户网站的各项业务需求。查看源码 -
(自适应)挖掘机大型采矿设备pbootcms网站源码下载本模板基于PbootCMS系统开发,专为重型机械设备行业设计,特别适合挖掘机、采矿设备、工程机械等工业设备展示。采用响应式布局技术,确保各类设备参数和图片在不同终端上都能清晰展示。查看源码 -
粉色家政月嫂保姆公司pbootcms网站模板(PC+WAP)为家政服务、月嫂保姆企业打造的营销型解决方案,基于PbootCMS内核开发,采用温馨粉色主题传递行业温度。PHP7.0+高性能架构支持SQLite/MySQL双数据库查看源码
| 分享笔记 (共有 篇笔记) |

