Skip to content

webliumteam/editor.js

Β 
Β 

Repository files navigation

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

IE / Edge
IE / Edge
Firefox
Firefox
Chrome
Chrome
Safari
Safari
iOS Safari
iOS Safari
Opera
Opera
Edge 12+ Firefox 18+ Chrome 49+ Safari 10+ Safari 10+ Opera 36+

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.

πŸ‘‰ https://opencollective.com/editorjs

πŸ‘‰ Bitcoin: 3DCCemgtE6GrzehVpU6Sa2RJHFUUh8iT9q

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 are 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 on team@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 a whole Changelog

So 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.

So how to use the Editor after Installation.

  • Create new Blocks by Enter or with 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.

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

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

Shortcuts

We really appreciate shortcuts. So there are few presets.

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

Also we support shortcuts on the all type of Tools. Specify a shortcut with the Tools configuration. For example:

var editor = new EditorJS({
  //...
  tools: {
    header: {
      class: Header,
      shortcut: 'CMD+SHIFT+H'
    },
    list: {
      class: List,
      shortcut: 'CMD+SHIFT+L'
    }
  }
  //...
 });

Installation Guide

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

  1. Load Editor's core
  2. Load Tools
  3. Initialize Editor's instance

Load Editor's core

Firstly you need to 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
  • Local file from project

Node.js

Install the package via NPM or Yarn

npm i @editorjs/editorjs

Include module in your application

const EditorJS = require('@editorjs/editorjs');

Use from CDN

You can load specific version of package from jsDelivr CDN.

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

Then require this script.

<script src="..."></script>

Save sources to project

Copy editor.js file to your project and load it.

<script src="editor.js"></script>

Load Tools

Each Block at the Editor.js is represented by Tools. There are simple external scripts with their own logic. Probably you want to use several Block Tools that should be connected.

For example check out our Header Tool that represents heading blocks.

You can install Header Tool by the same way as the Editor (Node.js, CDN, local file).

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

Example: use Header from CDN

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

Create Editor instance

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

<div id="editorjs"></div>

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.

var editor = new EditorJS(); /** Zero-configuration */

// equals

var editor = new EditorJS('editorjs');

Or pass a whole settings object.

var editor = new EditorJS({
    /**
     * Create a holder for the Editor and pass its ID
     */
    holder : 'editorjs',

    /**
     * Available Tools list.
     * Pass Tool's class or Settings object for each Tool you want to use
     */
    tools: {
        header: {
          class: Header,
          inlineToolbar : true
        },
        // ...
    },

    /**
     * Previously saved data that should be rendered
     */
    data: {}
});

Saving Data

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

editor.save()
  .then((savedData) => {
    console.log(savedData);
  });

Example

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

Credits and references

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

codex.so

About

A block-styled editor with clean JSON output

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 87.9%
  • CSS 5.7%
  • HTML 5.3%
  • JavaScript 1.1%