ckeditor使用技巧总结
介绍
官方开发者文档: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使用技巧总结的更多相关文章
- CKEditor使用配置方法
一.使用方法: 1.在页面<head>中引入ckeditor核心文件ckeditor.js <script type="text/javascript" src= ...
- CKEditor的使用方法
CKEditor的使用方法 2014-03-31 09:44 8649人阅读 评论(1) 收藏 举报 版权声明:本文为博主原创文章,未经博主允许不得转载. ckeditor 的官方网站是 http:/ ...
- ckeditor的详细配置
CKEditor 3 JavaScript API Documentation : http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.con ...
- CKeditor 配置使用
CKeditor 配置使用 一.使用方法:1.在页面<head>中引入ckeditor核心文件ckeditor.js<script type="text/javascrip ...
- 网络编辑器插件ckeditor+ckfinder配置
原帖地址 另外一个 去掉编辑器的下边栏 在config.js中加入: config.removePlugins = 'elementspath'; config.resize_enabled = fa ...
- ckeditor的配置及使用
一.使用方法:1.在页面<head>中引入ckeditor核心文件ckeditor.js<script type="text/javascript" src=&q ...
- ckeditor与ckfinder简单整合使用
Ckeditor与ckfinder简单整合使用 功能:主要用来发送图文的email,图片上传到本地服务器,但是email的图片地址要写上该服务器的远程地址(图片地址:例如:http://www.bai ...
- CKEditor上传视频(java)
CKEditor上传视频 CKEditor批量上传图片flvplayer.swf播放器CKEditor整合包(v4.6.1) ------------------------------------ ...
- 富文本编辑器 CKeditor 配置使用 (带附件)
Ckeditor下载地址:http://ckeditor.com/download 1.CKeditor的基本配置 var textval=CKEDITOR.instances.TextArea1.g ...
- ckeditor使用说明
2015-08-17 15:42热心网友最快回答 一.使用方法:1.在页面<head>中引入ckeditor核心文件ckeditor.js<script type="t ...
随机推荐
- [转帖]在 Linux 上以 All-in-One 模式安装 KubeSphere
https://www.kubesphere.io/zh/docs/v3.4/quick-start/all-in-one-on-linux/ 对于刚接触 KubeSphere 并想快速上手该容器平台 ...
- [转帖]如何查看Docker容器环境变量,如何向容器传递环境变量
https://www.cnblogs.com/larrydpk/p/13437535.html 1 前言 欢迎访问南瓜慢说 www.pkslow.com获取更多精彩文章! 了解Docker容器的运行 ...
- [转帖]一文读懂 HugePages(大内存页)的原理
https://juejin.cn/post/6956541214426398757 在介绍 HugePages 之前,我们先来回顾一下 Linux 下 虚拟内存 与 物理内存 之间的关系. 物理内存 ...
- [转帖]Jmeter压力测试工具安装及使用教程
https://www.cnblogs.com/monjeo/p/9330464.html 一.Jmeter下载 进入官网:http://jmeter.apache.org/ 1.第一步进入官网如下图 ...
- [转帖]java获取到heapdump文件后,如何快速分析?
https://www.jianshu.com/p/aaf56385766d 简介 在之前的OOM问题复盘之后,本周,又一Java服务出现了内存问题,这次问题不严重,只会触发堆内存占用高报警,没有 ...
- [转帖]官网:Nacos的授权验证
https://nacos.io/zh-cn/docs/v2/guide/user/auth.html 注意 Nacos是一个内部微服务组件,需要在可信的内部网络中运行,不可暴露在公网环境,防止带来安 ...
- Windows 磁盘部分性能数据获取
Windows 磁盘部分性能数据获取 摘要 每次晚上加班总有收获 这次发现了一个fio for windows版本的压测程序, 准备学习和使用一下. https://github.com/axboe/ ...
- [转帖]总结:Tomcat的IO模型
一.介绍 对于 linux 操作系统,IO 多路复用使用的是 epoll 方式,对于 windows 操作系统中 IO 多路复用使用的是 iocp 方式,对于 mac 操作系统 IO 多路复用使用的是 ...
- Grafana监控java应用以及vCenter的方法
Grafana监控java应用以及vCenter的方法 背景 最开始弄过vCenter的监控. 但是发现很多地方已经不合适了. 今天看了下jmx监控 java的应用. 顺便监控了下vCenter. 这 ...
- vue3中context.emit遇见的坑
场景描述 今天遇见一个问题 ,子组件向上抛出去的事件. 被执行了两次,原因是 context.emit('click', item.id) 你的事件名是click 将click更改为其他事件名称,就可 ...