介绍

官方开发者文档:CKEditor 4 documentation

技巧总结

1.挑选需要的插件,打包下载

参考:CKEditor 4.4.1 添加代码高亮显示插件功能--使用官方推荐Code Snippet插件_djl的专栏,blog.djl.cx好记-CSDN博客

2.config.js的常用配置

全部配置:Class Config (CKEDITOR.config) - CKEditor 4 API docs

CKEDITOR.editorConfig = function( config ) {
config.toolbar = 'Full';
config.toolbarLocation = 'top';
config.height = 700;
config.toolbar = [
// { name: 'document', items: [ 'Source'] },
// { name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', '-', 'Undo', 'Redo' ] },
// { name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ], items: [ 'Find', 'Replace' ] },
//{ name: 'forms', items: [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton' ] },
// '/',
{ name: 'basicstyles', groups: [ 'basicstyles'], items: [ 'Bold', 'Italic', 'Underline', 'Strike'] },
{ name: 'paragraph', groups: [ 'list', 'blocks' ], items: [ 'NumberedList', 'BulletedList', '-', 'Blockquote' ] },
{ name: 'links', items: [ 'Link' ] },
{ name: 'insert', items: [ 'Image', 'Table', 'HorizontalRule'] },
{ name: 'styles', items: [ 'Styles', 'Format', 'FontSize','CodeSnippet' ] },
{ name: 'colors', items: [ 'TextColor', 'BGColor' ] },
{ name: 'tools', items: [ 'Maximize' ] }
]; config.plugins = 'dialogui,dialog,basicstyles,blockquote,button,toolbar,clipboard,menu,filetools,filebrowser,floatingspace,listblock,font,format,horizontalrule,wysiwygarea,image,menubutton,link,list,liststyle,maximize,pastetext,tab,table,tabletools,tableselection,lineutils,uploadwidget,uploadimage,textwatcher,htmlwriter,undo';
config.skin = 'moono-lisa';
config.resize_enabled = false; //禁止拖拽改变尺寸
config.removePlugins = 'elementspath'; //删除底边栏
config.image_previewText=' '; //清空图片上传预览的内容
config.image_prefillDimensions = false; //禁止图片上传完毕后自动填充图片长和宽
config.imageUploadUrl = '/post/upload'; //图片上传接口
config.filebrowserImageUploadUrl= '/post/upload';
config.extraPlugins = 'wordcount,codesnippet'; //其他插件:字数统计、提示信息、语法高亮
config.wordcount = {
showParagraphs: false, // 是否统计段落数
showWordCount: false, // 是否统计词数
showCharCount: true, // 是否统计字符数
countSpacesAsChars: false, // 是否统计空间字符
countHTML: false, // 是否统计包括HTML字符的字符数
maxWordCount: -1, // 最大允许词数,-1表示无上限
maxCharCount: -1, //最大允许字符数,-1表示无上限
filter: new CKEDITOR.htmlParser.filter({ //添加筛选器添加或删除元素之前计数(CKEDITOR.htmlParser.filter),默认值:null (no filter)
elements: {
div: function( element ) {
if(element.attributes.class == 'mediaembed') {
return false;
}
}
}
})
};
config.codeSnippet_theme = 'github'; //添加中文字体
//config.font_names="宋体/SimSun;新宋体/NSimSun;仿宋_GB2312/FangSong_GB2312;楷体_GB2312/KaiTi_GB2312;黑体/SimHei;微软雅黑/Microsoft YaHei;幼圆/YouYuan;华文彩云/STCaiyun;华文行楷/STXingkai;方正舒体/FZShuTi;方正姚体/FZYaoti;"+ config.font_names;
};

3.配置图片上传接口

参考:ckeditor富文本编辑器的使用和图片上传,复制粘贴图片上传_sayoko06的博客-CSDN博客_ckeditor上传图片

@ResponseBody
@PostMapping("/upload")
public String upload(@RequestParam("upload") MultipartFile file, HttpServletRequest request, HttpServletResponse response){
FileResponse fileResponse = new FileResponse();
String fileName = file.getOriginalFilename();
String suffixName = fileName.substring(fileName.lastIndexOf("."));
String newFileName = IDUtils.getUUID()+suffixName;
Calendar cal = Calendar.getInstance();
int month = cal.get(Calendar.MONTH) + 1;
int year = cal.get(Calendar.YEAR);
String uploadPath = baseUploadPath+ File.separator+String.valueOf(year)+File.separator+String.valueOf(month);
File uploadPathFile = new File(uploadPath);
if(!uploadPathFile.exists()){
uploadPathFile.mkdirs();
} //System.out.println("上传路径:"+uploadPath); try {
String realPath = uploadPath+File.separator+newFileName;
file.transferTo(new File(baseUploadPath+newFileName));
// return {"uploaded":1, "fileName" : "image.png", "url":"http://localhost:15593/UploadImages/RickEditorFiles/Content/2017-05-23 10_39_54.png" };
return fileResponse.success(1, newFileName, ckeditorAccessImageUrl + newFileName, null);
// return "{\"uploaded\" : 1, \"fileName\" : \"image.png\", \"url\": , \"error\" : { \"message\":\"\" } }";
} catch (IOException e) {
e.printStackTrace();
return fileResponse.error(0,"系统异常!");
} }

4.初始化CKEDITOR

<textarea id="editor" name="editor" rows="80"
style="width: 99.4%; display: none; visibility: hidden;"></textarea>
<script>
// 初始化编辑器
CKEDITOR.replace('editor');
</script>

5.获取编辑器中HTML文本

postContent = CKEDITOR.instances.editor.getData().trim();

6.获取编辑器中纯文本

postTextContent = CKEDITOR.instances.editor.document.getBody().getText();

7.代码高亮显示

参考:CKEditor 4.4.1 添加代码高亮显示插件功能--使用官方推荐Code Snippet插件_djl的专栏,blog.djl.cx好记-CSDN博客

8.显示代码行号?

hljs.initLineNumbersOnLoad();

ckeditor使用技巧总结的更多相关文章

  1. CKEditor使用配置方法

    一.使用方法: 1.在页面<head>中引入ckeditor核心文件ckeditor.js <script type="text/javascript" src= ...

  2. CKEditor的使用方法

    CKEditor的使用方法 2014-03-31 09:44 8649人阅读 评论(1) 收藏 举报 版权声明:本文为博主原创文章,未经博主允许不得转载. ckeditor 的官方网站是 http:/ ...

  3. ckeditor的详细配置

    CKEditor 3 JavaScript API Documentation : http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.con ...

  4. CKeditor 配置使用

    CKeditor 配置使用 一.使用方法:1.在页面<head>中引入ckeditor核心文件ckeditor.js<script type="text/javascrip ...

  5. 网络编辑器插件ckeditor+ckfinder配置

    原帖地址 另外一个 去掉编辑器的下边栏 在config.js中加入: config.removePlugins = 'elementspath'; config.resize_enabled = fa ...

  6. ckeditor的配置及使用

    一.使用方法:1.在页面<head>中引入ckeditor核心文件ckeditor.js<script type="text/javascript" src=&q ...

  7. ckeditor与ckfinder简单整合使用

    Ckeditor与ckfinder简单整合使用 功能:主要用来发送图文的email,图片上传到本地服务器,但是email的图片地址要写上该服务器的远程地址(图片地址:例如:http://www.bai ...

  8. CKEditor上传视频(java)

    CKEditor上传视频 CKEditor批量上传图片flvplayer.swf播放器CKEditor整合包(v4.6.1) ------------------------------------ ...

  9. 富文本编辑器 CKeditor 配置使用 (带附件)

    Ckeditor下载地址:http://ckeditor.com/download 1.CKeditor的基本配置 var textval=CKEDITOR.instances.TextArea1.g ...

  10. ckeditor使用说明

      2015-08-17 15:42热心网友最快回答 一.使用方法:1.在页面<head>中引入ckeditor核心文件ckeditor.js<script type="t ...

随机推荐

  1. Raid卡型号的简单辨认与问题发现过程

    Raid卡型号的简单辨认与问题发现过程 背景 同事给了一个awr报告. !-_-! 其实我看不懂. 但是他告诉我 有大量的log file sync 的等待事件. 然后又给了一套其他的文件, 发现lo ...

  2. [转帖]ramfs、tmpfs、rootfs、ramdisk介绍

    ramfs.tmpfs.rootfs.ramdisk介绍   bootleader--->kernel---->initrd(是xz.cpio.是ramfs的一种,主要是驱动和为了加载ro ...

  3. [转帖]为什么不推荐使用/etc/fstab

    https://www.jianshu.com/p/af49a5d0553f 对于工作中使用服务器的公司来讲,每到节假日来临时,总免不了对服务器进行下电.而收假回来的早上,则会有一个早上的时间会花费在 ...

  4. [转帖]Percolator分布式事务模型原理与应用

    https://zhuanlan.zhihu.com/p/59115828 Percolator 模型 Percolator[1] 是 Google 发表在 OSDI'2010 上的论文 Large- ...

  5. [转帖]linux删除文本文件空白行

    linux删除文本文件空白行https://www.zhihu.com/people/chen-kai-84-54-75 sed命令 在Linux中,可以使用sed命令批量删除文本中的空白行.以下是一 ...

  6. [转帖]Innodb存储引擎-备份和恢复(分类、冷备、热备、逻辑备份、二进制日志备份和恢复、快照备份、复制)

    文章目录 备份和恢复 分类 冷备 热备 逻辑备份 mysqldump SELECT...INTO OUTFILE 恢复 二进制日志备份与恢复 快照备份(完全备份) 复制 快照+复制的备份架构 备份和恢 ...

  7. 微信小程序之某个节点距离顶部和底部的距离 createSelectorQuery

    这个方法可以用来在上滑滚动的时候,让某一个区域置顶, 在下滑的时候,又变为原来的位置哈! <huadong :class="{'hident':isFixed}" id=&q ...

  8. 洛谷P3101 题解

    输入格式 第 \(1\) 行,三个整数 \(m,n,t\). 第 \(2\) 到 \(m+1\) 行,\(m\) 个整数,表示海拔高度. 第 \(2+m\) 到 \(2m+1\) 行,\(m\) 个整 ...

  9. Machine Learning | Coursera 课后代码

    Machine Learning | Coursera GitHub地址:https://github.com/hanlulu1998/Coursera-Machine-Learning Machin ...

  10. vue脚手架创建与环境安装

    1.安装 Node.jsDownload | Node.js 在这里下载的是最新版,如果要安装以前的版本,页面往下拉找到 Previous Releases-Donloads-下载msi文件. ​​ ...