How to Easily Parse Editor.js Clean Data to HTML

Apr 24, 2024 | Programming

Parsing data from the Editor.js format into HTML can be a daunting task, especially if you’re working with various frameworks like JavaScript, TypeScript, React, Angular, or Vue. Fortunately, there’s a lightweight and efficient utility called editorjs-html that promises an easy journey in converting your Editor.js clean data to HTML. Let’s dive into the process!

Installation

Getting started is straightforward. Follow the steps based on your preferred setup:

Usage

Once you’ve installed the library, it’s time to put it to work. Depending on your environment, the usage differs slightly:

For Browser

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

For Node.js

const edjsHTML = require('editorjs-html');
const edjsParser = edjsHTML();
const html = edjsParser.parse(editorjs_clean_data);
console.log(html);

Supported Block Types

The editorjs-html library supports various block types including:

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

Parsing Editor.js Data

There are multiple ways to parse your Editor.js data:

Entire Editor.js Data Object

const edjsParser = edjsHTML();
const HTML = edjsParser.parse(editorjs_data);
console.log(HTML);

Single Clean Data Block

const edjsParser = edjsHTML();
const blockHTML = edjsParser.parseBlock(editorjs_data_block);
console.log(blockHTML);

Extending for Custom Blocks

Want to render custom Editor.js blocks? No problem! You can extend the editorjs-html functionality by defining custom parsers:

function customParser(block) {
    return `${block.data.text}`;
}
const edjsParser = edjsHTML({ custom: customParser });

Troubleshooting

If you encounter issues or need more insights into how to use this library, here are some suggestions:

  • Ensure you’ve installed the library correctly using NPM or by downloading the required files.
  • Check your console for any parsing errors which might indicate what went wrong.
  • Refer to the Releases for updates and potential bug fixes.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Conclusion

The editorjs-html library offers a fast, efficient, and lightweight way to parse Editor.js clean data to HTML. Its customizability and support for multiple frameworks make it a fantastic choice for web developers. Remember to leverage the extendable features for custom block rendering and enjoy a seamless integration.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox