Home

Awesome

Anchor block tune for Editor.js

This Editor.js block tune enables users to add or remove an anchor to any block tool. Anchors provide the ability to target specific HTML elements within a webpage, aiding in seamless navigation.

A few points to note:

Preview

preview

Installation

Using npm

npm install @coolbytes/editorjs-anchor

Using yarn

yarn add @coolbytes/editorjs-anchor

Usage

To make it available to all block tools:

const editor = new EditorJS({
  tools: {
    anchor: Anchor
  },
  tunes: ['anchor']
});

To make it available to a particular block tool:

const editor = new EditorJS({
  tools: {
    anchor: Anchor,
    paragraph: {
      class: Paragraph,
      tunes: ['anchor']
    }
  }
});

Config Params

FieldTypeDescription
maxWordsnumberMaximum number of words for the anchor value
maxCharsnumberMaximum number of characters for the anchor value

 

[!NOTE] (Default behavior) If neither maxWords nor maxChars are specified, the entire inner text of the element is used (ideal for adding anchors to header elements).

[!NOTE] Only alphabets, numbers, and underscores are retained. Spaces and hyphens are replaced with underscores.

[!NOTE] When both maxWords and maxChars are provided, maxWords takes precedence.

 

const editor = EditorJS({
  tools: {
    anchor: {
      class: Anchor,
      config: {
        maxWords: 4
      }
    }
  },
  tunes: ['anchor']
});

Output data

TypeDescription
stringAnchor value

 

Example for Paragraph Tool:

{
  "type": "paragraph",
  "data": {
    "text": "Some paragraph to test the anchor block tune"
  },
  "tunes": {
    "anchor": "Some paragraph to test"
  }
}