Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A renderer for editorjs block data to react components

License

NotificationsYou must be signed in to change notification settings

cevinw/editorjs-react-parser

Repository files navigation

A renderer for editorjs block data to react components

This project aims to simplify rendering correct semantic html tags out of editorjs output data to react elements

The goal is to support all block types and tunes specified in theawesome list, currently this project supports these block tools.

This whole component can function as both a server component or client component.

Installation

npm i editor-react-parser

Tip

If you wish to use the default tailwind styling include this in your tailwind.config file

"content": ["./node_modules/editor-react-parser/dist/*/**.{js,ts}",]

Usage

This parser is built to be flexible but with a low bar of entry.

Add this component to any other component. And feed it with the complete output data object from editor js

<BlockParserdata={editorJsData}/>

This component allows all styles and default config to be overriden by a config object.If you are using typescript you can use the included type BlockParserConfig to get hints on what can be done.

[!NOTE] >Only the fields you override will override the default config

importReactfrom"react";importBlockParser,{OutputData}from"editor-react-parser";constExample=()=>{consteditorJsData:OutputData={version:"2.29.1",time:newDate().getTime(),blocks:[{id:"Kp5hXEi74T",type:"paragraph",data:{text:"test paragraph",},},],};return(<div><BlockParserdata={editorJsData}/></div>);};exportdefaultExample;

Classes and styling

The Editor Js react parser relies on using tailwind styles to render some components,if you do not wish to use tailwind you should include classes for components through the configuration objectComponents such as columns rely on using grid-cols from tailwind in order to correctly render multiple columns.

Configuring code syntax highlighting

We strongly recommend you to configure the syntax highlighting if you wish to use it.If this parser is used with@rxpm/editor-js-codeor other code tools providing languages you could add the following configurations

code:{  languages:[{language:"rust",displayText:"Rust",logoAlt:"rust logo",logoSrc:"/code-logos/rust.svg",shortName:"rs",},{language:"python",displayText:"Python",logoAlt:"Python logo",logoSrc:"/code-logos/python.svg",shortName:"py",},{language:"typescript",displayText:"Typescript",logoAlt:"Typescript logo",logoSrc:"/code-logos/typescript.svg",shortName:"ts",},{language:"java",displayText:"Java",logoAlt:"Java logo",logoSrc:"/code-logos/java.svg",shortName:"java",},{language:"typescript",displayText:"Typescript [tsx]",logoAlt:"tsx logo",logoSrc:"/code-logos/react.svg",shortName:"tsx",},];}

The logo src in this particular configuration will use the "./public" folder and produce something looking like thiscode example

Tip

You can usedevicon resource to find good quality svg code logos.

Example of the tools object configuration

 code:{class:CodeTool,config:{modes:{'ts':'TypeScript','py':'Python','rs':'Rust','tsx':'TypeScriptXML','java' :"Java"},defaultMode:'ts'}},
Custom code style

You can add custom styles using react syntax highlighter styles. this can be done by adding the following configuration

import{idea}from"react-syntax-highlighter/dist/cjs/styles/hljs";constExample=()=>{constconfig:BlockParserConfig={code:{codeStyle:idea},};return(<div><BlockParserdata={editorJsData}config={config}/></div>);};

Inline tools

Since this parser uses html-react-parser in certain elements a lot of inline tools might work as intended.

Contributing

We welcome all contributors.To contribute clone the repo, create a new branch. Add your code and tests and submit a pull request.

A big thank you to all who might want to contribute 💖

About

A renderer for editorjs block data to react components

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp