0.0.4 • Published 4 months ago

editorjs-inline-formatter v0.0.4

Weekly downloads
-
License
-
Repository
-
Last release
4 months ago

editorjs-inline-formatter

Create an inline tool for (https://editorjs.io/) with text formatting tags (eg. bold, strong, em, u, ...).

Getting started

npm i editorjs-inline-formatter --save

# or
yarn add editorjs-inline-tool

Usage

This is an example where GenericInlineTool is used in a React app (using @natterstefan/react-editor-js). But this should work for any other framework as well.

// index.js
import EditorJs from '@natterstefan/react-editor-js'
import Header from '@editorjs/header'
import Paragraph from '@editorjs/paragraph'

import createGenericInlineTool, {
  ItalicInlineTool,
  UnderlineInlineTool,
} from 'editorjs-inline-formatter'

const TOOLS = {
  header: Header,
  paragraph: {
    class: Paragraph,
    inlineToolbar: true,
  },
  // add custom tags or overwrite default tools of editorjs by using the same
  // name (eg. `bold` or `italic`)
  bold: {
    class: createGenericInlineTool({
      sanitize: {
        strong: {},
      },
      shortcut: 'CMD+B',
      tagName: 'STRONG',
      toolboxIcon:
        '<svg class="icon icon--bold" width="12px" height="14px"><use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#bold"></use></svg>',
    }),
  },
  // or use a pre-defined tool instead
  italic: ItalicInlineTool,
  underline: UnderlineInlineTool,
}

const App = () => {
  return <EditorJs tools={TOOLS} data={data} />
}

Configuration

createGenericInlineTool returns an InlineTool for EditorJS. The following options are available:

NameRequiredTypeDefaultDescription
sanitizefalseobjectundefinedObject that defines rules for automatic sanitizing.
shortcutfalsestringundefinedShortcut to apply Tool's render and inserting behaviour
tagNametruestringundefinedtext formatting tag (eg. bold)
toolboxIcontruestringundefinedIcon for the tools inline toolbar

Additionally, there are pre-defined inline tools available: ItalicInlineTool, StrongInlineTool and UnderlineInlineTool (they can be found here).

0.0.3

4 months ago

0.0.4

4 months ago

0.0.2

4 months ago

0.0.2-next.2

6 months ago

0.0.2-next.1

6 months ago

0.0.2-next.0

6 months ago

0.0.1

6 months ago