前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ckeditor5-基础使用

ckeditor5-基础使用

作者头像
ianzhi
发布2019-07-31 12:49:21
3.6K0
发布2019-07-31 12:49:21
举报
文章被收录于专栏:LNMP开发那些事LNMP开发那些事

最近在找一个富文本编辑器,找来找去,不是太丑,就是太过于陈旧,不利于在vue或者其他js前端框架中移植。不过还好最终找到了ckeditor5,颜值和功能都很让我满意,比较恶心的就是文档只有英文的,而且整个api的文档,根本不知道该看哪。在耗费了一天的功夫看文档以后,我决定还是自己来整理一份速查手册类似的文档,以方便大家如果有使用富文本编辑器的需要,也可以有一个参考。这里是ckeditor5系列文章的第一篇《基础使用》。

  1. ckeditor5-基础使用

其实ckeditor是一个老项目了,但是相对于其他的编辑器,它是一直在保持更新的,目前最新的版本就是ckeditor 5,这里以经典编辑器样式(Classic Editor)来做介绍,其他(Inline, Ballon,Document)与此相同。

一、安装

官方提供三种方式安装:

  • CDN
  • npm
  • zip压缩包下载

1、CDN

CDN结构:<script src="https://cdn.ckeditor.com/ckeditor5/[version.number]/[distribution]/ckeditor.js"></script>

其中的version.number,distribution需要替换成你要使用的版本号和编辑器类型,版本号请到官网查询,编辑器类型可以参照下面:

  • classic - the Classic editor
  • inline - the Inline editor
  • balloon - the Balloon editor
  • decoupled-document - the Document editor

2、npm

这个没有什么好说,直接执行npm命令即可。

npm install --save @ckeditor/ckeditor5-build-classic 

Or: 

npm install --save @ckeditor/ckeditor5-build-inline 

Or: 

npm install --save @ckeditor/ckeditor5-build-balloon 

Or: 

npm install --save @ckeditor/ckeditor5-build-decoupled-document

3.zip包下载

点击下载ckeditor压缩包

二、基础使用

快速在自己的网页里放入编辑器还是比较简单的,只需要以下一个步骤:

1、html中添加一个元素用来放编辑器

<textarea name="content" id="editor"></textarea>

2、引入编辑器js,这里使用cdn

<script src="https://cdn.ckeditor.com/ckeditor5/11.1.1/classic/ckeditor.js"></script>

3、调用ClassicEditor.create方法,来初始化编辑器

<script> 

ClassicEditor

.create( document.querySelector( '#editor' ) ) 

.catch( error => { console.error( error ); } );

 </script>

4、完整例子

<!DOCTYPE html> 

<html lang="en"> 

<head> 

<meta charset="utf-8">

 <title>CKEditor 5 – Classic editor</title> 

<script src="https://cdn.ckeditor.com/ckeditor5/11.1.1/classic/ckeditor.js"></script>

 </head>

 <body> 

<h1>Classic editor</h1> 

<textarea name="content" id="editor">

 &lt;p&gt;This is some sample content.&lt;/p&gt;

 </textarea> 

<script> 

ClassicEditor 

.create( document.querySelector( '#editor' ) ) 

.catch( error => { console.error( error ); } ); </script> 

</body>

 </html>

这样,ckeditor5就出现在我们的页面中了~~~

文章作者ianzhi,原文地址:https://cloud.tencent.com/developer/article/1476862

文章版权归作者所有,转载请保留此声明。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-10-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、安装
    • 1、CDN
      • 2、npm
      • Or: 
      • Or: 
      • Or: 
        • 3.zip包下载
          • 二、基础使用
            • 1、html中添加一个元素用来放编辑器
            • 2、引入编辑器js,这里使用cdn
            • 3、调用ClassicEditor.create方法,来初始化编辑器
            • 4、完整例子
        相关产品与服务
        内容分发网络 CDN
        内容分发网络(Content Delivery Network,CDN)通过将站点内容发布至遍布全球的海量加速节点,使其用户可就近获取所需内容,避免因网络拥堵、跨运营商、跨地域、跨境等因素带来的网络不稳定、访问延迟高等问题,有效提升下载速度、降低响应时间,提供流畅的用户体验。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档