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> </p>
but I want to display it like this:
This is a random text i typed
- First item
- Second item
- third item
How can I solve this?
Change this:
<%= result.FormatedText %>
To this:
<%- result.FormatedText %>
It outputs the unescaped value, the browser could now render it.
Check the documentation.