CXEditor :CXEditor官网
注意:务必按照俺的步骤,按照官网步骤十有八九都会跳坑里。
注意:我用的Vue3是基于Vite构建
npm init vue@latest
npm install --save @ckeditor/ckeditor5-vue @ckeditor/ckeditor5-build-classic
main.js
import { createApp } from 'vue'
import App from './App.vue'
import CKEditor from '@ckeditor/ckeditor5-vue';
createApp(App).use(CKEditor).mount('#app')
App.vue
注意:
克隆的这个CXEditor5是专门安装插件与自定义插件用的,与vue3里的CXEditor5没有联系 ↓
命令
git clone -b stable https://github.com/ckeditor/ckeditor5
cd ckeditor5/packages/ckeditor5-build-classic
注: cd的路径别搞错了。
注:
运行克隆的CXEditor5
以上操作无误后,执行 npm run build
, 成功后打开ckeditor5\packages\ckeditor5-build-classic\sample\index.html
预览效果,若可以预览,证明成功,开始进入下一步↓
打开CXEditor5压缩包里的package.json配置,复制配置devDependencies里所有以 @ckeditor/xxxxxx 开头的插件。
粘贴到克隆的CXEditor5的ckeditor5\packages\ckeditor5-build-classic\package.json
的devDependencies中,有重复的删除重复的即可
我的 package.json 参考如下
{
"name": "@ckeditor/ckeditor5-build-classic",
"version": "35.3.2",
"description": "The classic editor build of CKEditor 5 – the best browser-based rich text editor.",
"keywords": [
"ckeditor5-build",
"ckeditor",
"ckeditor5",
"ckeditor 5",
"wysiwyg",
"rich text",
"editor",
"html",
"contentEditable",
"editing",
"operational transformation",
"ot",
"collaboration",
"collaborative",
"real-time",
"framework"
],
"main": "./build/ckeditor.js",
"files": [
"build",
"ckeditor5-metadata.json",
"CHANGELOG.md"
],
"dependencies": {
"@ckeditor/ckeditor5-adapter-ckfinder": "^35.3.2",
"@ckeditor/ckeditor5-autoformat": "^35.3.2",
"@ckeditor/ckeditor5-basic-styles": "^35.3.2",
"@ckeditor/ckeditor5-block-quote": "^35.3.2",
"@ckeditor/ckeditor5-ckbox": "^35.3.2",
"@ckeditor/ckeditor5-ckfinder": "^35.3.2",
"@ckeditor/ckeditor5-cloud-services": "^35.3.2",
"@ckeditor/ckeditor5-easy-image": "^35.3.2",
"@ckeditor/ckeditor5-editor-classic": "^35.3.2",
"@ckeditor/ckeditor5-essentials": "^35.3.2",
"@ckeditor/ckeditor5-heading": "^35.3.2",
"@ckeditor/ckeditor5-image": "^35.3.2",
"@ckeditor/ckeditor5-indent": "^35.3.2",
"@ckeditor/ckeditor5-link": "^35.3.2",
"@ckeditor/ckeditor5-list": "^35.3.2",
"@ckeditor/ckeditor5-media-embed": "^35.3.2",
"@ckeditor/ckeditor5-paragraph": "^35.3.2",
"@ckeditor/ckeditor5-paste-from-office": "^35.3.2",
"@ckeditor/ckeditor5-style": "^35.3.2",
"@ckeditor/ckeditor5-table": "^35.3.2",
"@ckeditor/ckeditor5-typing": "^35.3.2"
},
"devDependencies": {
"@ckeditor/ckeditor5-adapter-ckfinder": "^35.3.2",
"@ckeditor/ckeditor5-autoformat": "^35.3.2",
"@ckeditor/ckeditor5-autosave": "^35.3.2",
"@ckeditor/ckeditor5-basic-styles": "^35.3.2",
"@ckeditor/ckeditor5-block-quote": "^35.3.2",
"@ckeditor/ckeditor5-ckfinder": "^35.3.2",
"@ckeditor/ckeditor5-cloud-services": "^35.3.2",
"@ckeditor/ckeditor5-editor-classic": "^35.3.2",
"@ckeditor/ckeditor5-essentials": "^35.3.2",
"@ckeditor/ckeditor5-find-and-replace": "^35.3.2",
"@ckeditor/ckeditor5-font": "^35.3.2",
"@ckeditor/ckeditor5-heading": "^35.3.2",
"@ckeditor/ckeditor5-highlight": "^35.3.2",
"@ckeditor/ckeditor5-horizontal-line": "^35.3.2",
"@ckeditor/ckeditor5-html-support": "^35.3.2",
"@ckeditor/ckeditor5-image": "^35.3.2",
"@ckeditor/ckeditor5-indent": "^35.3.2",
"@ckeditor/ckeditor5-link": "^35.3.2",
"@ckeditor/ckeditor5-list": "^35.3.2",
"@ckeditor/ckeditor5-media-embed": "^35.3.2",
"@ckeditor/ckeditor5-mention": "^35.3.2",
"@ckeditor/ckeditor5-paragraph": "^35.3.2",
"@ckeditor/ckeditor5-paste-from-office": "^35.3.2",
"@ckeditor/ckeditor5-restricted-editing": "^35.3.2",
"@ckeditor/ckeditor5-table": "^35.3.2",
"@ckeditor/ckeditor5-typing": "^35.3.2",
"@ckeditor/ckeditor5-word-count": "^35.3.2",
"@ckeditor/ckeditor5-style":"^35.3.2",
"@ckeditor/ckeditor5-alignment": "^35.3.2",
"@ckeditor/ckeditor5-core": "^35.3.2",
"@ckeditor/ckeditor5-dev-utils": "^31.0.0",
"@ckeditor/ckeditor5-dev-webpack-plugin": "^31.0.0",
"@ckeditor/ckeditor5-theme-lark": "^35.3.2",
"css-loader": "^5.2.7",
"postcss-loader": "^4.3.0",
"raw-loader": "^4.0.1",
"style-loader": "^2.0.0",
"terser-webpack-plugin": "^4.2.3",
"ts-loader": "^9.3.0",
"webpack": "^5.58.1",
"webpack-cli": "^5.0.1"
},
"engines": {
"node": ">=14.0.0",
"npm": ">=5.7.1"
},
"author": "CKSource (http://cksource.com/)",
"license": "GPL-2.0-or-later",
"homepage": "https://ckeditor.com/ckeditor-5",
"bugs": "https://github.com/ckeditor/ckeditor5/issues",
"repository": {
"type": "git",
"url": "https://github.com/ckeditor/ckeditor5.git",
"directory": "packages/ckeditor5-build-classic"
},
"scripts": {
"build": "webpack --mode production",
"preversion": "npm run build"
}
}
打开在线打包好的CXEditor5压缩包,复制src\ckeditor.js
的所有代码。
粘贴到克隆的ckeditor5\packages\ckeditor5-build-classic\src\ckeditor.js
中,全部覆盖该文件的代码。
打包的时候我说过,不需要在意导航栏的顺序,这里可以用代码调整导航栏顺序。
调整defaultConfig
里的toolbar
的item数组,可调整导航栏顺序。
我的 ckeditor.js 参考
/**
* @license Copyright (c) 2014-2022, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
*/
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor.js';
import Alignment from '@ckeditor/ckeditor5-alignment/src/alignment.js';
import Autoformat from '@ckeditor/ckeditor5-autoformat/src/autoformat.js';
import AutoImage from '@ckeditor/ckeditor5-image/src/autoimage.js';
import AutoLink from '@ckeditor/ckeditor5-link/src/autolink.js';
import Autosave from '@ckeditor/ckeditor5-autosave/src/autosave.js';
import BlockQuote from '@ckeditor/ckeditor5-block-quote/src/blockquote.js';
import Bold from '@ckeditor/ckeditor5-basic-styles/src/bold.js';
import CKFinder from '@ckeditor/ckeditor5-ckfinder/src/ckfinder.js';
import CKFinderUploadAdapter from '@ckeditor/ckeditor5-adapter-ckfinder/src/uploadadapter.js';
import CloudServices from '@ckeditor/ckeditor5-cloud-services/src/cloudservices.js';
import Code from '@ckeditor/ckeditor5-basic-styles/src/code.js';
import DataFilter from '@ckeditor/ckeditor5-html-support/src/datafilter.js';
import Essentials from '@ckeditor/ckeditor5-essentials/src/essentials.js';
import FindAndReplace from '@ckeditor/ckeditor5-find-and-replace/src/findandreplace.js';
import FontBackgroundColor from '@ckeditor/ckeditor5-font/src/fontbackgroundcolor.js';
import FontColor from '@ckeditor/ckeditor5-font/src/fontcolor.js';
import FontFamily from '@ckeditor/ckeditor5-font/src/fontfamily.js';
import FontSize from '@ckeditor/ckeditor5-font/src/fontsize.js';
import GeneralHtmlSupport from '@ckeditor/ckeditor5-html-support/src/generalhtmlsupport.js';
import Heading from '@ckeditor/ckeditor5-heading/src/heading.js';
import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight.js';
import HorizontalLine from '@ckeditor/ckeditor5-horizontal-line/src/horizontalline.js';
import Image from '@ckeditor/ckeditor5-image/src/image.js';
import ImageCaption from '@ckeditor/ckeditor5-image/src/imagecaption.js';
import ImageInsert from '@ckeditor/ckeditor5-image/src/imageinsert.js';
import ImageResize from '@ckeditor/ckeditor5-image/src/imageresize.js';
import ImageStyle from '@ckeditor/ckeditor5-image/src/imagestyle.js';
import ImageToolbar from '@ckeditor/ckeditor5-image/src/imagetoolbar.js';
import ImageUpload from '@ckeditor/ckeditor5-image/src/imageupload.js';
import Indent from '@ckeditor/ckeditor5-indent/src/indent.js';
import IndentBlock from '@ckeditor/ckeditor5-indent/src/indentblock.js';
import Italic from '@ckeditor/ckeditor5-basic-styles/src/italic.js';
import Link from '@ckeditor/ckeditor5-link/src/link.js';
import LinkImage from '@ckeditor/ckeditor5-link/src/linkimage.js';
import List from '@ckeditor/ckeditor5-list/src/list.js';
import ListProperties from '@ckeditor/ckeditor5-list/src/listproperties.js';
import MediaEmbed from '@ckeditor/ckeditor5-media-embed/src/mediaembed.js';
import MediaEmbedToolbar from '@ckeditor/ckeditor5-media-embed/src/mediaembedtoolbar.js';
import Mention from '@ckeditor/ckeditor5-mention/src/mention.js';
import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph.js';
import PasteFromOffice from '@ckeditor/ckeditor5-paste-from-office/src/pastefromoffice.js';
import StandardEditingMode from '@ckeditor/ckeditor5-restricted-editing/src/standardeditingmode.js';
import Strikethrough from '@ckeditor/ckeditor5-basic-styles/src/strikethrough.js';
import Style from '@ckeditor/ckeditor5-style/src/style.js';
import Subscript from '@ckeditor/ckeditor5-basic-styles/src/subscript.js';
import Table from '@ckeditor/ckeditor5-table/src/table.js';
import TableCaption from '@ckeditor/ckeditor5-table/src/tablecaption.js';
import TableCellProperties from '@ckeditor/ckeditor5-table/src/tablecellproperties';
import TableColumnResize from '@ckeditor/ckeditor5-table/src/tablecolumnresize.js';
import TableProperties from '@ckeditor/ckeditor5-table/src/tableproperties';
import TableToolbar from '@ckeditor/ckeditor5-table/src/tabletoolbar.js';
import TextTransformation from '@ckeditor/ckeditor5-typing/src/texttransformation.js';
import Title from '@ckeditor/ckeditor5-heading/src/title.js';
import TodoList from '@ckeditor/ckeditor5-list/src/todolist';
import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline.js';
import WordCount from '@ckeditor/ckeditor5-word-count/src/wordcount.js';
class Editor extends ClassicEditor {}
// Plugins to include in the build.
Editor.builtinPlugins = [
Alignment,
Autoformat,
AutoImage,
AutoLink,
Autosave,
BlockQuote,
Bold,
CKFinder,
CKFinderUploadAdapter,
CloudServices,
Code,
DataFilter,
Essentials,
FindAndReplace,
FontBackgroundColor,
FontColor,
FontFamily,
FontSize,
GeneralHtmlSupport,
Heading,
Highlight,
HorizontalLine,
Image,
ImageCaption,
ImageInsert,
ImageResize,
ImageStyle,
ImageToolbar,
ImageUpload,
Indent,
IndentBlock,
Italic,
Link,
LinkImage,
List,
ListProperties,
MediaEmbed,
MediaEmbedToolbar,
Mention,
Paragraph,
PasteFromOffice,
StandardEditingMode,
Strikethrough,
Style,
Subscript,
Table,
TableCaption,
TableCellProperties,
TableColumnResize,
TableProperties,
TableToolbar,
TextTransformation,
Title,
TodoList,
Underline,
WordCount
];
// Editor configuration.
Editor.defaultConfig = {
toolbar: {
items: [
'undo',
'redo',
'heading',
'|',
'bold',
'italic',
'subscript',
'strikethrough',
'underline',
'|',
'fontColor',
'fontBackgroundColor',
'fontSize',
'fontFamily',
'highlight',
'|',
'insertTable',
'link',
'blockQuote',
'code',
'horizontalLine',
'findAndReplace',
'|',
'bulletedList',
'numberedList',
'todoList',
'restrictedEditingException',
'|',
'outdent',
'indent',
'alignment',
'|',
'imageUpload',
'mediaEmbed',
'imageInsert',
'CKFinder',
'style'
],
shouldNotGroupWhenFull: true//导航栏自动折行
},
language: 'zh',
image: {
toolbar: [
'imageTextAlternative',
'toggleImageCaption',
'imageStyle:inline',
'imageStyle:block',
'imageStyle:side',
'linkImage'
]
},
table: {
contentToolbar: [
'tableColumn',
'tableRow',
'mergeTableCells',
'tableCellProperties',
'tableProperties'
]
}
};
export default Editor;
执行 nmp run build
打包,打包成功后运行ckeditor5\packages\ckeditor5-build-classic\sample\index.html
,如图,添加的功能已经有了
注意路径,别搞错了。
复制克隆的CXEditor5该路径下所有文件ckeditor5\packages\ckeditor5-build-classic\build
,如图,把里面的所有文件复制到剪切板
粘贴到vue3中的day\node_modules\@ckeditor\ckeditor5-build-classic\build
路径下,替换所有文件。
耶,完美运行。
在线打包时,部分插件没有添加一起打包,可以手动安装插件。
安装插件和上面一样的原理,npm下载插件到克隆的ckeditor5\packages\ckeditor5-build-classic\node_modules\@ckeditor
文件夹里。
在ckeditor5\packages\ckeditor5-build-classic\src\ckeditor.js
js文件里导入、配置好插件。
然后npm run build 克隆的CXEditor5,成功后,把 run 成功的文件,也就是这个路径下的所有文件\ckeditor5\packages\ckeditor5-build-classic\build
,复制到vue3对应路径下。
替换所有文件,大功告成,插件就按装好了。
注:一定要在克隆的CXEditor5,npm run build 成功后再复制到vue3项目中。
可能看完教程的小伙伴有点懵,我在这里细说下载的文件、克隆的文件、vue3的文件
一共下载了3个CXEditor5
npm install --save @ckeditor/ckeditor5-vue @ckeditor/ckeditor5-build-classic
git clone -b stable https://github.com/ckeditor/ckeditor5
https://ckeditor.com/ckeditor-5/online-builder/
复制官网打包的ckeditor.js与package.json配置。
粘贴到克隆的CXEditor5对应文件中。
在克隆的CXEditor5项目下npm run build无误后,将build的文件复制到vue3。
配置的css
.ck.ck-content {
font-family: 'PT Serif', serif;
font-size: 16px;
line-height: 1.6;
padding: 2em;
}
.ck-content .ck-horizontal-line {
margin-bottom: 1em;
}
.ck.ck-content hr {
width: 100px;
border-top: 1px solid #aaa;
height: 1px;
margin: 1em auto;
}
.ck.ck-content h3.category {
font-family: 'Bebas Neue';
font-size: 20px;
font-weight: bold;
color: #d1d1d1;
letter-spacing: 10px;
margin: 0;
padding: 0;
}
.ck.ck-content h2.document-title {
font-family: 'Bebas Neue';
font-size: 50px;
font-weight: bold;
margin: 0;
padding: 0;
border: 0;
}
.ck.ck-content h3.document-subtitle {
font-size: 20px;
color: #e91e63;
margin: 0 0 1em;
font-weight: normal;
padding: 0;
}
.ck.ck-content p.info-box {
--background-size: 30px;
--background-color: #e91e63;
padding: 1.2em 2em;
border: 1px solid var(--background-color);
background: linear-gradient(135deg, var(--background-color) 0%, var(--background-color) var(--background-size), transparent var(--background-size)), linear-gradient(135deg, transparent calc(100% - var(--background-size)), var(--background-color) calc(100% - var(--background-size)), var(--background-color));
border-radius: 10px;
margin: 1.5em 2em;
box-shadow: 5px 5px 0 #ffe6ef;
}
.ck.ck-content blockquote.side-quote {
font-family: 'Bebas Neue';
font-style: normal;
float: right;
width: 35%;
position: relative;
border: 0;
overflow: visible;
z-index: 1;
margin-left: 1em;
}
.ck.ck-content blockquote.side-quote::before {
content: "“";
position: absolute;
top: -37px;
left: -10px;
display: block;
font-size: 200px;
color: #e7e7e7;
z-index: -1;
line-height: 1;
}
.ck.ck-content blockquote.side-quote p {
font-size: 2em;
line-height: 1;
}
.ck.ck-content blockquote.side-quote p:last-child:not(:first-child) {
font-size: 1.3em;
text-align: right;
color: #555;
}
.ck.ck-content span.marker {
background: yellow;
}
.ck.ck-content span.spoiler {
background: #000;
color: #000;
}
.ck.ck-content span.spoiler:hover {
background: #000;
color: #fff;
}
.ck.ck-content pre.fancy-code {
border: 0;
margin-left: 2em;
margin-right: 2em;
border-radius: 10px;
}
.ck.ck-content pre.fancy-code::before {
content: "";
display: block;
height: 13px;
background: url(data:image/svg+xml;base64,PHN2ZyBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1NCAxMyI+CiAgPGNpcmNsZSBjeD0iNi41IiBjeT0iNi41IiByPSI2LjUiIGZpbGw9IiNGMzZCNUMiLz4KICA8Y2lyY2xlIGN4PSIyNi41IiBjeT0iNi41IiByPSI2LjUiIGZpbGw9IiNGOUJFNEQiLz4KICA8Y2lyY2xlIGN4PSI0Ny41IiBjeT0iNi41IiByPSI2LjUiIGZpbGw9IiM1NkM0NTMiLz4KPC9zdmc+Cg==);
margin-bottom: 8px;
background-repeat: no-repeat;
}
.ck.ck-content pre.fancy-code-dark {
background: #272822;
color: #fff;
box-shadow: 5px 5px 0 #0000001f;
}
.ck.ck-content pre.fancy-code-bright {
background: #dddfe0;
color: #000;
box-shadow: 5px 5px 0 #b3b3b3;
}
↓
↓
↓
解决方法:↓
↓
CKeditor5相关问题
End
2022/12/14 14:39 一次修改
2022/12/17 12:23 二次修改