@calumk/editorjs-codecup

中文文档
1.3.0发布于 2025/03/10MITCommonJS近 30 天下载 2.7万

Codecup, for EditorJS

原始使用文档
文档目录9 节
  1. NPM
  2. JS
  3. About
  4. Demo
  5. Built with:
  6. Installation / Use
  7. Language Selection
  8. Data Format
  9. Contributing

EditorJs - CodeCup

NPM

npm i @calumk/editorjs-codecup

JS

https://cdn.jsdelivr.net/npm/@calumk/editorjs-codecup@latest

About

This is an EditorJs wrapper for CodeCup - A lovely lightweight zero-dep code formatter

It was built to be an improvement on :

Demo

Demo

Built with:


Installation / Use

import EditorJS from '@editorjs/editorjs';
import editorjsCodecup from '@calumk/editorjs-codecup';

var editor = new EditorJS({
  // ...
  tools: {
    ...
    code : editorjsCodecup
  },
});

Language Selection

The plugin provides two ways to handle language selection:

  1. Free-form Language Input: By default (when no languages are configured), users can enter any valid Prism.js language key through a text input.

  2. Predefined Language Dropdown: When you provide a languages configuration, users can select from a predefined list of languages through a dropdown menu.

You can configure the language selection behavior using these options:

Predefined Languages

Provide a custom mapping of Prism.js language keys to their display names:

var editor = new EditorJS({
  // ...
  tools: {
    code: {
      class: editorJsCodeCup,
      config: {
        languages: { 
          javascript: "JavaScript",
          python: "Python",
          java: "Java",
          cpp: "C++",
          csharp: "C#",
          go: "Go",
          none: "Plain Text",
        }
      } 
    }
  },
});

Force Show Language Input

If you want to allow both predefined language selection AND free-form language input, use the forceShowLanguageInput option:

var editor = new EditorJS({
  // ...
  tools: {
    code: {
      class: editorJsCodeCup,
      config: {
        languages: { 
          javascript: "JavaScript",
          python: "Python",
          // ... other languages
        },
        forceShowLanguageInput: true // Shows both dropdown and language input
      } 
    }
  },
});

Refer to Prism.js supported languages for the available language mappings.

Data Format

The data imported/exported from the block is as follows:

NameDescription
codeThe code that is displayed in the editor, with line breaks
language (optional)The programming language
showlinenumbers (optional)Will show/hide the line numbers (Default true)
showCopyButton (optional)Will show/hide the copy button (Default true)

Since language and linenumbers are optional, existing code blocks can safley use this plugin


Contributing

@calumk

@keertyverma

版本与发布记录

@calumk/editorjs-codecup 共发布 10 个版本,首次发布于 2024/01/12;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.3.0latest2025/03/101.7 年前
1.2.02024/08/102 年前
1.1.12024/01/252 年前
1.1.02024/01/252 年前
1.0.62024/01/232 年前
1.0.52024/01/152 年前

关于 @calumk/editorjs-codecup 的常见问题

@calumk/editorjs-codecup 是什么?

Codecup, for EditorJS

如何安装 @calumk/editorjs-codecup?

在项目目录运行 npm install @calumk/editorjs-codecup,或使用 pnpm add / yarn add / bun add。

@calumk/editorjs-codecup 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/calumk__editorjs-codecup 是否存在。

@calumk/editorjs-codecup 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@calumk/editorjs-codecup 可以商用吗?

@calumk/editorjs-codecup 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@calumk/editorjs-codecup 的下载量有多少?

根据 npm 官方下载统计,@calumk/editorjs-codecup 在 2026/10/09 – 2026/11/07 这 30 天内被下载 27,297 次,日均约 910 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@calumk/editorjs-codecup 还在维护吗?

最新版本 1.3.0 发布于 2025/03/10(1.7 年前);至今共发布 10 个版本,其中过去 12 个月发布了 0 个;首次发布于 2024/01/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。