@magnolia/ckeditor5-build
v2.0.0
Published
Magnolia CKEditor 5 plugins enable editors to link pages and assets from Magnolia into rich text content, as well as to embed assets.
Readme
Custom CKEditor 5 editor built for integration with Magnolia
Installation
In order to rebuild the application you need to install all dependencies first. To do it, open the terminal in the project directory and type:
npm installMake sure that you have the node and npm installed first. If not, then follow the instructions on the Node.js documentation page.
Adding or removing plugins
You can add new plugin by two common ways that have the same result:
Use
npm installcommand, e.g:npm install @ckeditor/[email protected] --saveOr manually add the plugin to the dependencies section of the
packages/ckeditor5-build/package.json"dependencies": { //other dependencies ... "@ckeditor/ckeditor5-highlight": "^41.2.1" }
To remove the plugin, simply remove it out of the dependencies section and run npm install command
Importing plugins to the CKEDITOR build
You can import any installed plugins to CKEDITOR build by following steps:
- Locate the
ckeditor5.tsunderpackages/ckeditor5-build/src - Add import statement to the
ckeditor5.ts, e.g:import { Highlight } from '@ckeditor/ckeditor5-highlight';
Rebuilding editor
If you have already done the Installation and Adding or removing plugins steps, you're ready to rebuild the editor by running the following command:
npm run buildThis will build the CKEditor 5 to the build directory. You can open your browser and you should be able to see the changes you've made in the code. If not, then try to refresh also the browser cache by typing Ctrl + R or Cmd + R depending on your system.
Local development
To develop CKEditor5 build and plugins and make them available to use in your Magnolia instance
Install and build the package:
npm install && npm run buildnpm run start, now the package is accessible via http://127.0.0.1:9090/ckeditor5.js or http://localhost:9090/ckeditor5.js
Inject the build to Magnolia Rich Text Field powered by CkEditor 5
- Configure the microprofile property
magnolia.ckeditor5.buildwith the url to the running package, e.g:magnolia.ckeditor5.build=http://localhost:9090/ckeditor5.js. Note that, any change to your build will be watched and be in time updated. - Run your instance
The application will be rebuilt on-the-fly after any change. Please note that
build/ckeditor.jsis only rebuilt when runningnpm run build.- Configure the microprofile property
Customize build
To customize CKEditor5 build and plugins and make it available to use in your Magnolia instance
- Install and build the package
npm install && npm run build
- Inject the build to Magnolia Rich Text Field powered by CkEditor 5
- Find the
ckeditor5.jsfile underpackages/ckeditor5-build/build - Place the
ckeditor5.jsfile in yourlight-module/websresources. E.glight-modules/module-lm/webresources/ - Config the
magnolia.ckeditor5.buildproperty with the path to the ckeditor5.js. E.g:-Dmagnolia.ckeditor5.build=light-module/module-lm/webresources/ckeditor5.js
- Find the
- Run your instance
Debugging
To debug the CKEditor 5 instance on your browser, you need to attach that instance to the ckeditor-inspector.
Prerequisite: https://unpkg.com/@ckeditor/ckeditor5-inspector/build/inspector.js is attached to the field.
- In the browser, create a bookmark on the Bookmark bar
- In the
Namefield, fill anything you want, e.g.CKEditor Inspector - In the
Urlfield, copy and paste the code below
javascript:(function(){
let script=document.createElement('script');
script.src='https://unpkg.com/@ckeditor/ckeditor5-inspector/build/inspector.js';
script.onload=()=> {
CKEditorInspector.attachToAll();
setTimeout(() => {
const inspectorContainer = document.querySelector('.ck-inspector');
if (inspectorContainer) {
inspectorContainer.style.zIndex = '10000';
}
}, 1000);
};
document.head.appendChild(script);
})()- Then click
Save - Open the form, which contains ckeditor5 fields, then click to the saved bookmark, let's says
CKEditor Inspector, et voila, you will notice there is a small toolbar at the bottom of the page.
