GithubHelp home page GithubHelp logo

510074793 / codebox Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dev-juju/codebox

0.0 0.0 0.0 487 KB

Code highlighting tool for Editor.js

License: Other

JavaScript 12.97% TypeScript 73.92% CSS 13.11%

codebox's Introduction

CodeBox

Code syntax highlighting tool for Editor.js

Setup

Install the package via NPM

npm i @bomdi/codebox

Add to your module/application

import CodeBox from '@bomdi/codebox';
OR
const CodeBox = require('@bomdi/codebox');

Usage

Add CodeBox tools property of the CodeX Editor initial config.

const CodexEditor = require('@editorjs/editorjs');

let editor = new CodexEditor({
  ...

  tools: {
    ...
    codeBox: {
      class: CodeBox,
      config: {
        themeURL: 'https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/dracula.min.css', // Optional
        themeName: 'atom-one-dark', // Optional
        useDefaultTheme: 'light' // Optional. This also determines the background color of the language select drop-down
      }
    },
  }

  ...
});

Config Params

All parameters are optional

Field Type Description
themeURL string URL pointing to CSS file that can be used by highlight.js. This could also point o your own custom CSS syntax file. If themeURL is provided, themeName and useDefaultTheme will be ignored
themeName string Any one of the accepted theme names used by highlight.js. Only the name is required, not the full URL (example "a11y-dark"). If themeName is provided, useDefaultTheme will be ignored
useDefaultTheme string CodeBox has 2 default themes - 1 light and 1 dark. You can specify what default should be applied by passing the string 'light' or 'dark' to this parameter. Note that setting themeURL or themeName overrides this setting for the main code block, however, the background of the language select element/dropdown menu is set by this value

If no parameters are specified, CodeBox defaults to a dark theme.

Output data

CodeBox returns the following data

{
  "type": "codeBox",
  "data": {
    "code": "consttest = newTest();.codeBoxTextArea{\n  width: 100%;\n  min-height: 30px;\n  padding: 10px;\n  border-radius: 2px 2px 2px 0;\n  border: none !important;\n  outline: none !important;\n  font: 14px monospace;\n}\n\n.codeBoxSelectDiv{\n  display: flex;\n  flex-direction: column;\n  justify-content: flex-start;\n  align-items: flex-start;\n  position: relative;\n}",
    "language": "css",
    "theme": "https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/atom-one-dark.min.css"
  }
}

Render saved data as component

If you use react, you can pass your saved data to the library editorjs-react-renderer to render a code block component

import { CodeBoxOutput } from 'editorjs-react-renderer';

const data = {
  "type": "codeBox",
  "data": {
    "code": ".codeBoxTextArea{\n  width: 100%;\n  min-height: 30px;\n  padding: 10px;\n  border-radius: 2px 2px 2px 0;\n  border: none !important;\n  outline: none !important;\n  font: 14px monospace;\n}\n\n.codeBoxSelectDiv{\n  display: flex;\n  flex-direction: column;\n  justify-content: flex-start;\n  align-items: flex-start;\n  position: relative;\n}",
    "language": "css",
    "theme": "https://cdn.jsdelivr.net/gh/highlightjs/[email protected]/build/styles/atom-one-dark.min.css"
  }
};

const CodeBlock = () => CodeBoxOutput(data);

export default CodeBlock;

Author

Dev Juju

Contact Us

Learn

codebox's People

Contributors

dev-juju avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.