Replacing Text with HTML Tags in Syncfusion Text Editor for React

We are using the Syncfusion Text Editor and need to replace certain portions of the text using JavaScript based on API responses. The challenge lies in replacing the text while maintaining its HTML tags within the editor to preserve the formatting. We are looking for a method or approach that can help us modify the text within the editor while retaining its HTML tags and original formatting.


3 Replies

SK Selvaprakash Karuppusamy Syncfusion Team September 4, 2023 03:34 PM UTC

Hi Fatos,


You can use our LoadString API on the server side to convert HTML to SFDT and use the paste API to insert the converted SFDT with format in the document editor. Please refer to the below sample and UG documentation to know about how to use LoadString and paste APIs.

EJ2-Document-Editor-Web-Services/ASP.NET Core/src/Controllers/DocumentEditorController.cs at master · SyncfusionExamples/EJ2-Document-Editor-Web-Services (github.com)


Editor API in React DocumentEditor API component - Syncfusion

we have used the canvas to render the elements, so the above one is a possible way to replace the text using HTML content. And please confirm if the above solution meets your requirements.



LA Leutrim Ahmeti September 4, 2023 03:36 PM UTC

Hi Selvaprakash,


Thanks for the response. We're using React in the front-end code. This seems to be done in ASP.NET. Do you have an alternative solution for React?



SK Selvaprakash Karuppusamy Syncfusion Team September 5, 2023 09:13 AM UTC

Hi Fatos,


We don't support direct HTML importing on the client side. So, we have used the Syncfusion Docio server library on the server side for parsing the documents. So, in your case,

HTML document opening

We support the SFDT for file opening, so on the server side, we converted the HTML or other document editor-supported format documents into SFDT and used that SFDT for file opening on the client side.

Insert HTML content into the document editor.

As we said in the previous update, you can use our LoadString API on the server side to convert HTML to SFDT and use the paste API to insert the converted SFDT in the document editor. Please refer to the below sample and UG documentation to learn about how to use LoadString and paste APIs.

LoadString API -  https://github.com/SyncfusionExamples/EJ2-Document-Editor-Web-Services/blob/master/ASP.NET%20Core/src/Controllers/DocumentEditorController.cs#L256

Paste API - https://ej2.syncfusion.com/react/documentation/api/document-editor/editor/#paste

And the server needed for parsing the documents. You can deploy web APIs for server-side dependencies of the Document Editor component on the following platforms:

Wed services - SyncfusionExamples/EJ2-Document-Editor-Web-Services: This repository contains Web API service projects for Word Processor (also known as Document Editor) component server-side dependencies in all supported platforms. (github.com) 



Loader.
Up arrow icon