Skip to content

Link with target & rel attribute for Editor.js

Notifications You must be signed in to change notification settings

dldevinc/editorjs-hyperlink

 
 

Repository files navigation

Hyperlink Tool

A tool link with target & rel attribute for Editor.js.

Screen Shot 2020-11-08 at 23 51 36

Screen Shot 2020-11-08 at 23 51 43

Screen Shot 2020-11-08 at 23 52 04

Installation

Get the package via NPM

npm i -D git+ssh://git@github.com:dldevinc/editorjs-hyperlink.git#bdaf684

Include module at your application

const Hyperlink = require('editorjs-hyperlink');

Usage

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

var editor = EditorJS({
  ...
  
  tools: {
    ...

    hyperlink: {
      class: Hyperlink,
      config: {
        shortcut: 'CMD+L',
        target: '_blank',
        rel: 'nofollow',
        availableTargets: ['_blank', '_self'],
        availableRels: ['author', 'noreferrer'],
        validate: false,
      }
    },

    ...
  },

  ...

  i18n: {
    toolNames: {
      Hyperlink: 'Link'
    },
    tools: {
      hyperlink: {
        Save: 'Salvar',
        'Select target': 'Seleziona destinazione',
        'Select rel': 'Wählen rel'
      }
    }
  }
  
  ...
});

Config Params (optional)

Field Type Description
className string Defines a class attribute, defaults to null
shortcut string Shortcut, defaults to 'CMD+L'
target string Defines a default target, defaults to null
rel string or string[] Defines a default rel, defaults to null
availableTargets string[] Available link targets, defaults to all targets.
If empty array is provided, the control will be hidden and the default value applied.
availableRels string[] Available link rels, defaults to all rels.
If empty array is provided, the control will be hidden and the default value applied.
validate boolean Defines if an URL should be validated on saving
configure function Function that accepts URL and returns attributes object with optional fields: {href:"https://...",target:"_blank",rels:{nofollow: true}}

License

MIT

About

Link with target & rel attribute for Editor.js

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 87.1%
  • CSS 6.9%
  • HTML 6.0%