how to display html effect for the plaintext with html tags

225 Views Asked by At

I'm using TinyMCE in the text editor to style the input text

while I'm inserting that text input into the database it is stored with Html tags like below

<p>Hello</p> <strong>buddy</strong>

when I retrieve the data from the database, it displaying the text with Html tags only and not displaying the HTML effect

How can I get the text with HTML effect!

Any idea or any suggestions?

Thanks in Advance

1

There are 1 best solutions below

4
Chirag Paryani On

I suppose you're trying to add a codesample which is HTML in your case. But when you save it and render the tinyMCE editor again it interprets it as HTML content and not text content. Kindly correct me if my understanding of your question is wrong

If i am right in understanding your problem, below is your solution

  1. You need to enter the HTML block of code via a plugin which is codesample rather than directly pasting it in the editor text box. Here is the link for your reference https://www.tiny.cloud/docs/plugins/opensource/codesample/
  2. When you are rerendering the HTML block in editor or elsewhere. There are chances that it might still interpret it as HTML. To resolve that you'll have to escape HTML characters before rendering

If you can help me with a pen ( https://fiddle.tiny.cloud/ ), I'll be able to give more insights based on your usecase

Cheers!

[UPDATE post clarification of doubt]

You can use a script to first capture the content and set the html via JS script, something like below

<div class="content_from_editor">
  <strong>Hello</strong>
</div>
<script>
 var htmlData = document.getElementById('app');
 document.getElementById('app').innerHTML = htmlData;
</script>