2.5.1 • Published 4 years ago

@chanhha/editorjs-header v2.5.1

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Heading Tool

Version of EditorJS that the plugin is compatible with

Customize Headings Blocks from the original at EditorJS Header.

This customize is about to use along with EditorJS Title. Because pasteConfig is hardedcode, we can't paste the H1 tag to Title Tool.

I change behavior of pasteConfig following the config for levels.

Installation

Install via NPM

Get the package

npm i --save @editorjs/header

Include module at your application

const Header = require('@editorjs/header');

Download to your project's source dir

  1. Upload folder dist from repository
  2. Add dist/bundle.js file to your page.

Load from CDN

You can load specific version of package from jsDelivr CDN.

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

Then require this script on page with Editor.js.

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

Usage

Add a new Tool to the tools property of the Editor.js initial config.

var editor = EditorJS({
  ...

  tools: {
    ...
    header: Header,
  },

  ...
});

Shortcut

You can insert this Block by a useful shortcut. Set it up with the tools[].shortcut property of the Editor's initial config.

var editor = EditorJS({
  ...

  tools: {
    ...
    header: {
      class: Header,
      shortcut: 'CMD+SHIFT+H',
    },
  },

  ...
});

Config Params

All properties are optional.

FieldTypeDescription
placeholderstringheader's placeholder string
levelsnumber[]enabled heading levels
defaultLevelnumberdefault heading level
var editor = EditorJS({
  ...

  tools: {
    ...
    header: {
      class: Header,
      config: {
        placeholder: 'Enter a header',
        levels: [2, 3, 4],
        defaultLevel: 3
      }
    }
  }

  ...
});

Tool's settings

An image showing the header block tool

You can select one of six levels for heading.

Output data

FieldTypeDescription
textstringheader's text
levelnumberlevel of header: 1 for H1, 2 for H2 ... 6 for H6
{
  "type": "header",
  "data": {
    "text": "Why Telegram is the best messenger",
    "level": 2
  }
}