After the EditorJS processes the saved block data, the hyperlink is displayed as an <a> tag

"content": "{\"time\":1725957883405,\"blocks\":[{\"id\":\"ILZ-IPMJxE\",\"type\":\"paragraph\",\"data\":{\"text\":\"&lt;a href=\\\"https://google.com\\\">google.com&lt;/a>\",\"alignment\":\"left\"},\"tunes\":{\"textVariant\":\"\"}},{\"id\":\"Cq-LYzxhkR\",\"type\":\"delimiter\",\"data\":{}},{\"id\":\"Acr0suJ5Jl\",\"type\":\"paragraph\",\"data\":{\"text\":\"asd\",\"alignment\":\"left\"},\"tunes\":{\"textVariant\":\"call-out\"}}],\"version\":\"2.30.5\"}",

Here is the generated blocks data which includes an initial hyperlink to google.com.

Issue: When re-rendering the data, the text was displayed as plain text rather than a clickable hyperlink

<a href="https://google.com">google.com</a>

I have a component called useEditor.tsx that manages the initialization of the EditorJS:

editorInstanceRef.current = new EditorJS({
                        holder: holderId,
                        tools,
                        autofocus: true,
                        data: initialData,
                        placeholder: 'Start typing your content here...',
                        readOnly,
                    });

Below is how I am handling my Editor.tsx component to render the initial data:

useEffect(() => {
            if (editorInstanceRef.current) {
                editorInstanceRef.current.isReady
                    .then(() => {
                        setIsEditorReady(true);
                        onReady && onReady();
                        if (initialData) {
                            editorInstanceRef
                                .current!.render({
                                    blocks: initialData.blocks,
                                })
                                .catch((error) =>
                                    console.error(
                                        'Error loading initial content:',
                                        error
                                    )
                                );
                        }
                    })
                    .catch((error) =>
                        console.error('Error during editor ready state:', error)
                    );
            }

            return () => {
                if (editorInstanceRef.current) {
                    editorInstanceRef.current.isReady
                        .then(() => {
                            editorInstanceRef.current?.destroy();
                            editorInstanceRef.current = null;
                        })
                        .catch((error) =>
                            console.error('Error during editor cleanup:', error)
                        );
                }
            };
        }, [initialData, editorInstanceRef, onReady]);

Answer №1

To overcome this challenge, you can utilize HTMLReactParser for parsing and displaying the HTML content, including any hyperlink tags present. Here is a demonstration of how to integrate it:

import HTMLReactParser from "html-react-parser";

Afterwards, you can incorporate it into your HTML elements like so:

HTMLReactParser(`<a href="https://example.com">example.com</a>`)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ensure Website Accessibility by Implementing Minimum Resolution Requirements

Is it possible to create a website that only opens on screens with a resolution of at least 1024 x 768, and displays an error message on unsupported resolutions? I've tried using JavaScript to achieve this, but haven't had any success. Any assis ...

Show a specific div using jQuery fadeIn() when the user reaches the top of an HTML section

The code below has a specific purpose: 1) Determine the current scroll position. 2) Locate the parent article and determine its offsetTop for each .popup_next which represents a section on the site. 3) Calculate an offset value by adding 30px to the off ...

Attempting to develop a search feature for a multi-layered array using JavaScript

I've been attempting to search through a multidimensional array in JavaScript, but I'm facing some issues. Specifically, I am looking to input the first number from one of the 3 rows and retrieve the entire row. Essentially, my goal is to extract ...

Navigating through directories (including nested ones) containing images in React Native; what's the best way to approach this

I am currently attempting to organize groups of images. Within the directory ./assets, there are several folders structured as follows: ./assets ├── 1x3 │ ├── 1.jpg │ ├── 2.jpg │ └── 3.jpg └── 3x3 ├── 1. ...

Error: The function bcrypt.checkPassword() is undefined and cannot be called

Upon logging in, I encountered an issue where the error message "TypeError: bcrypt.checkPassword is not a function" was displayed. Reviewing my code, I am puzzled as to why bcrypt.checkPassword is not recognized as a function. [bcrypt.js] var checkPassw ...

What is the best way to extract the body content from a Markdown file that includes Frontmatter

How can I retrieve the content of the body from my markdown file using front matter? Currently, it is displaying as undefined. What steps should I take to fix this issue? {latest.map(({ url, frontmatter }) => ( <PostCard url={url} content={frontmat ...

Is it possible to dynamically assign trigger and target divs to bPopup?

On our ColdFusion page, we have a dynamic list of paired divs created using a loop over a query. For example, each pair consists of internshipHandleX and internshipHiddenX: <div id="internshipHidden#internship.currentrow#" class="hidden pop-up"> We ...

react-map-gl - Token not passing through environmental variable

DEV SERVER ISSUE if I directly input my api token in .env NEXT_PUBLIC_MAPBOX_API="my-secret-mapbox-gl-api-key" and use it like mapboxAccessToken={process.env.NEXT_PUBLIC_MAPBOX_API} but the map doesn't render and an error shows up in dev t ...

I'm having trouble getting the second controller to function properly in my AngularJS application

I've been looking everywhere for a solution on how to implement two controllers, but I can't seem to get it working. Could there be something wrong with my HTML or could the issue lie in my script? Here is the JavaScript code: <script> v ...

Is there a way to update specific content within a view in express.js without having to re-render the entire view?

I'm in the process of creating a calendar that allows users to click on dates, triggering a popup window displaying events for that specific date. The challenge lies in not knowing which date the user will click on prior to rendering, making it diffic ...

Connecting an AngularJS directive to a controller

I'm in the process of learning AngularJS directives and facing a challenge. Here's the JSFiddle link to an example I'm working on: https://jsfiddle.net/7smor9o4/ In the example, my expectation is for the vm.alsoId variable to match the valu ...

Angular utilizes array format to store data in the $scope

I am working on an Angular test application where I am trying to retrieve data from a PHP page into my model. The response comes using the echo json_encode($arr); command in the PHP file and has the format [{"id":"1","name":"first","text":"description"}]. ...

Algorithm for encryption and decryption using symmetric keys

Can anyone recommend a reliable symmetric-key encryption algorithm that works seamlessly with both JavaScript and Java programming languages? I attempted to implement one myself, but encountered some complications related to encoding. ...

Generate customizable additional rows for a table

My current project involves adding details to a database through the use of AJAX and dynamically updating table rows. For example: ---- {Customer: dropdown menu} | {Description: textarea} | delete Add New Customer --- When the user clicks, a drop-d ...

Can we consider JavaScript callbacks to be atomic?

Ensuring synchronization of fields in two independent third-party databases hosted in different locations is crucial to me. Below is a snippet of my generic node / express js code: router.post ('url', function(req,res,next) { third_party_ap ...

Investigating Jquery Flip Card Issues

Looking to create a set of flip cards using HTML, CSS, and jQuery. Currently facing an issue where only the first card is flipping when clicked. Any suggestions on how to modify the jQuery code to make it work for all cards would be highly appreciated. C ...

I am having trouble displaying SASS styles in the browser after running webpack with node

In my current project for an online course, I am utilizing sass to style everything. The compilation process completes successfully without any errors, but unfortunately, the browser does not display any of the styles. The styles folder contains five file ...

Displaying an error message prior to submitting the form in an AngularJS form validation process

I have implemented form validation using angularjs, but I am encountering an issue where the error message is displayed upon page load instead of after an actual error. I have set up a validation summary using a directive. Can you please advise me on how t ...

Managing switch input in Node.js: A comprehensive guide

Feeling completely lost while attempting to gather input from a switch using Express. I'm aiming to create a real-time application where toggling the switch triggers a response on the server side. Utilizing Bootstrap, here's a snippet of the HTML ...

Convert AngularJS ng-repeat data received from Laravel API into a specific format

My Backend API is built on Laravel 5.2 and the Frontend uses AngularJS. During a Laravel validation process, I check for errors and return an error message if validation fails. However, when I display these errors on the frontend, they appear in the forma ...