MIT License

项目介绍

pavittarx/editorjs-html 是一个托管在 GitHub 上的开源项目,主要使用 TypeScript 编写,采用 MIT License 许可证,目前获得 379 个 Star、59 次 Fork。

仓库全名
pavittarx/editorjs-html
开源许可证
MIT License
Star 数
379
Fork 数
59
未关闭 Issue
4

README 摘要

editorjs-html A utility to parse editorjs clean data to HTML. Use it with plain Javascript/Typescript, React, Angular, Vue or any templating engine/framework of your choice. Fast, Efficient and Lightweight. Fully customizable to the core. Supports basic editorjs blocks which are customizable as well. Extend to parse your own blocks. Whats' new in v4? Complete Rewrite, latest dependencies with minimal API changes…

完整内容见 GitHub 原始 README 或本页 。

常见问题

editorjs-html 用什么语言开发?

主要使用 TypeScript 编写,采用 MIT License 许可证,目前有 379 个 Star。

editorjs-html 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 editorjs-html 的源码?

可以直接克隆仓库:git clone https://github.com/pavittarx/editorjs-html.git;安装与运行步骤见仓库 README。

editorjs-html 最近还在维护吗?

仓库最近一次更新为 1月21日,当前有 4 个未关闭 Issue;Star 数为 379,可作为社区活跃度的参考。

关于

A javascript library to parse editorjs clean data to html. It is adaptable and usable in all kind of projects.

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
876
价值分
282
活跃状态
活跃

语言占比

JavaScript
TypeScript

Release

README

editorjs-html

A utility to parse editorjs clean data to HTML.

  • Use it with plain Javascript/Typescript, React, Angular, Vue or any templating engine/framework of your choice.
  • Fast, Efficient and Lightweight.
  • Fully customizable to the core.
  • Supports basic editorjs blocks which are customizable as well.
  • Extend to parse your own blocks.

Whats’ new in v4?

  • Complete Rewrite, latest dependencies with minimal API changes.
  • Redundant parseStrict() and validate() functions are removed.
  • Strict mode is configurable via options.
  • Console errors if parser functions for block is not avaiable. Strict Mode throws errors.
  • Code is more readable, modular. It would make it easier to contribute and track changes.
  • Type definitions directly fetched from Editor.js, so development becomes easier.
  • Unit Testing with Jest.

Installation

Self Host, precompiled versions.

NPM

npm install editorjs-html

CDN

Usage

Browser

const edjsParser = edjsHTML();
let html = edjsParser.parse(editorjs_clean_data);
console.log(html);

Nodejs

const edjsHTML = require("editorjs-html");
const edjsParser = edjsHTML();
const html = edjsParser.parse(editorjs_clean_data);

console.log(html);

Updates

See Releases

Docs

Supported Block Types

  • Header (H1-H6)
  • Lists (Ordered & Unordered)
  • Nested Lists
  • Image
  • Delimiter
  • Paragraph
  • Quote
  • Code
  • Embed

Parse Entire EditorJS Data Object

const edjsParser = edjsHTML();
const HTML = edjsParser.parse(editorjs_data);
// returns array of html strings per block
console.log(HTML);

Parse Entire EditorJS Data Object (Strict Mode)

const edjsParser = edjsHTML();
const HTML = edjsParser.parse(editorjs_data);
// returns an error
if (HTML instanceof Error) throw HTML;

// in case of success, returns an array of strings
console.log(HTML);

Parse Single Clean Data Block

const edjsParser = edjsHTML();
const blockHTML = edjsParser.parseBlock(editorjs_data_block);
// returns string of html for this block
console.log(blockHTML);

Strict Mode

const edjsParser = edjsHTML({}, { strict: true });
// returns the list of missing parser functions
const blockHTML = edjsParser.parse(editorjs_data);
console.log(blockHTML);

Extend For Custom Blocks

editorjs-html supports extending and overriding parser functions for blocks.

  // Example Custom or Unrecognised Block
  {
    type: "custom",
    data: {
      text: "Hello World"
    }
 }

// Parse this block in editorjs-html
function customParser(block) {
  return `<custom-tag> ${block.data.text} </custom-tag>`;
}

const plugins = {
  // The keyname must match with the type of block you want to parse with this funcion
  custom: customParser,
  // ... add more or overwrite
};

const edjsParser = edjsHTML(plugins);

Contribution

Please add an issue, or open a PR for any bugs, review or suggestions.

New Parser Functions

  1. For additional parser functions, please add them to parsers/block-name. Check existing functions for suggestions.
  2. Test everyting works fine, with pnpm test && pnpm build.
  3. Open a PR, for review.
  4. Add tests in tests directory. Make sure your tests pass with appropriate coverage.

Suggestions & Recommendations

I would love to have your feedback and any suggestions. You can also let me know, if you need support for any more editorjs blocks.

Support

If you find this helpful, consider giving this repository a Star. You can also buy me a coffee here

License

MIT Public License

Author

@pavittarx

评论

暂无评论