Home

Awesome

Code Tool for Editor.js 2.0 with language selector compatible with PrismJs Language Codes

This a fork of Code Tool for the Editor.js that allows to include code examples along with language codes that are supported by PrismJs in your articles.

The list of languages supported is in languages.txt

Installation

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 latest version of this package from jsDelivr CDN.

https://cdn.jsdelivr.net/gh/paraswaykole/editor-js-code@latest/dist/bundle.js

Require this script on a 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: {
    ...
    code: CodeTool,
  }
  
  ...
});

Config Params

FieldTypeDescription
placeholderstringCode Tool's placeholder string

Output data

This Tool returns code.

{
    "type" : "code",
    "data" : {
        "code": "body {\n font-size: 14px;\n line-height: 16px;\n}",
        "languageCode": "css"
    }
}