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.
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.
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.
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?
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: