Editor.js

A block-styled editor with clean JSON output

README

undefined undefined undefined Backers on Open Collective Sponsors on Open Collective undefined Join the chat at https://gitter.im/codex-team/editor.js

[[[[[[
------------------------------------------------------
EdgeFirefoxChromeSafariSafariOpera

If you like a project 💗💗💗


If you like Editor.js you can support project improvements and development of new features with a donation to our collective.


Sponsors


Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]


### Backers

Thank you to all our backers! 🙏 [Become a backer]


Contributors


This project exists thanks to all the people who contribute.

We really welcome new contributors. If you want to make some code with us, please take a look at the Good First Tasks. You can write to us onteam@codex.so or via special Telegram chat, or any other way.

Documentation


Please visit https://editorjs.io/ to view all documentation articles.


You can join a Gitter-channel or Telegram-chat and ask a question.

Changelog


See the whole Changelog

How to use Editor.js


Basics


Editor.js is a Block-Styled editor. Blocks are structural units, of which the Entry is composed.
For example, Paragraph, Heading, Image, Video, List are Blocks. Each Block is represented by Plugin.
We have many ready-to-use Plugins and a simple API for creating new ones.

How to use the Editor after Installation.

- Create new Blocks by pressing Enter or clicking the Plus Button
- Press TAB or click on the Plus Button to view the Toolbox
- Press TAB again to leaf Toolbox and select a Block you need. Then press Enter.

undefined

- Select a text fragment and apply a style or insert a link from the Inline Toolbar

undefined

- Use the «three-dots» button on the right to open Block Settings. From here, you can move and delete a Block
or apply a Tool's settings, if it provided. For example, you can set a Heading level or List style.

undefined

Shortcuts


A few shortcuts are preset as available.

Shortcut | Action | Restrictions
-- | -- | --
TAB | Show/leaf a Toolbox. | On empty block
SHIFT+TAB | Leaf back a Toolbox. | While Toolbox is opened
ENTER | Create a Block | While Toolbox is opened and some Tool is selected
CMD+B | Bold style | On selection
CMD+I | Italic style | On selection
CMD+K | Insert a link | On selection

Each Tool can also have its own shortcuts. These are specified in the configuration of the Tool, for example:

  1. ``` js
  2. var editor = new EditorJS({
  3.   //...
  4.   tools: {
  5.     header: {
  6.       class: Header,
  7.       shortcut: 'CMD+SHIFT+H'
  8.     },
  9.     list: {
  10.       class: List,
  11.       shortcut: 'CMD+SHIFT+L'
  12.     }
  13.   }
  14.   //...
  15. });

  16. ```

Installation Guide


There are few steps to run Editor.js on your site.


Step 1. Load Editor's core


Get Editor.js itself. It is a minified script with Editor's core and some default must-have tools.

Choose the most usable method of getting Editor for you.

- Node package
- Source from CDN

Option A. NPM install

Install the package via NPM or Yarn

  1. ``` sh
  2. npm i @editorjs/editorjs
  3. ```

Include module in your application

  1. ``` js
  2. import EditorJS from '@editorjs/editorjs';
  3. ```

Option B. Use a CDN

You can load EditorJS directly from from jsDelivr CDN.

https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest

For example, place this in your HTML:

  1. ``` html
  2. <script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
  3. ```

Or download the bundle file and use it from your server.

  1. ``` html
  2. <script src="editor.js"></script>
  3. ```

Step 2. Load the Tools that you want to make available


Each Block is represented by a Tool. Tools are simple external scripts with their own logic. For example, there is a Header Tool into which you type your heading text. If you want to be able to use this, install the Header Tool the same way as the Editor (Node.js, CDN, local file).

Example: use Header from CDN

  1. ``` html
  2. <script src="https://cdn.jsdelivr.net/npm/codex.editor.header@2.0.4/dist/bundle.js"></script>
  3. ```

Check Editor.js's community to see more ready-to-use Tools.

Step 3. Create Editor instance


Create an instance of Editor.js and pass Configuration Object withholderId and tools list.

  1. ``` html
  2. <div id="editorjs"></div>
  3. ```

You can create a simple Editor with only default Paragraph Tool by passing a string with element's Id (wrapper for Editor) as a configuration param. Or use the default editorjs id for wrapper.

  1. ``` js
  2. var editor = new EditorJS(); /** Zero-configuration */

  3. // equals

  4. var editor = new EditorJS('editorjs');
  5. ````

Or pass a whole settings object.

  1. ``` js
  2. var editor = new EditorJS({
  3.     /**
  4.      * Create a holder for the Editor and pass its ID
  5.      */
  6.     holder : 'editorjs',

  7.     /**
  8.      * Available Tools list.
  9.      * Pass Tool's class or Settings object for each Tool you want to use
  10.      */
  11.     tools: {
  12.         header: {
  13.           class: Header,
  14.           inlineToolbar : true
  15.         },
  16.         // ...
  17.     },

  18.     /**
  19.      * Previously saved data that should be rendered
  20.      */
  21.     data: {}
  22. });
  23. ```

Saving Data


Call editor.save() and handle returned Promise with saved data.

  1. ``` js
  2. editor.save()
  3.   .then((savedData) => {
  4.     console.log(savedData);
  5.   });
  6. ```

Example


Take a look at the example.html to view more detailed examples.

Credits and references


- We use HTMLJanitor module in our Sanitizer module.

About team


We are CodeX and we build products for developers and makers.

Follow us on Twitter: twitter.com/codex_team

Feel free to contact: team@codex.so