Search code examples
javascriptnode.jsejsckeditor4.x

How do i display these formated text without HTML tags


I am using CKeditor 4 to format text and store it in a database with Node.js and MySQL. The data type i used to store this is TEXT. Everything is fine until it is stored in the database.
The problem is when i retrieve the text from the database and try to display it using an EJS variable as follows:

<%=result.FormatedText%> 

the browser displays the content in the EJS variable like this:

<p><strong>This is a random text i typed</strong></p> <ol> <li>First item</li> <li>Second item</li> <li>third item</li> </ol> <p>&nbsp;</p>

but I want to display it like this:

This is a random text i typed

  1. First item
  2. Second item
  3. third item

 

How can I solve this?


Solution

  • Change this:

    <%= result.FormatedText %> 
    

    To this:

    <%- result.FormatedText %>
    

    It outputs the unescaped value, the browser could now render it.

    Check the documentation.