0

I am writting a simple system displaying data from my JSON instead of using a database. Everything works fine except for the html tags, which are displayed as plain text. Also note that I am the only one able to write in the json file, that's why I want to display html tag from it.

So here is the output

From page : <p>Test <b>Big Test</b> <i>Italic Test</i>.</p>

From source : &lt;p&gt;Test &lt;b&gt;Big Test&lt;/b&gt; &lt;i&gt;Italic Test&lt;/i&gt;.&lt;/p&gt;

Here is the output I want : Test Big Test Italic Test.

Here is pretty much how I store it in my Json file :

{
  "table": [
    {
      "desc": "<p>Test <b>Big Test</b> <i>Italic Test</i>.</p>"
    }
  ]
}

I've tried many things from the internet without a lot of many success. I am using express.

Here is how I parse it (note that there are many fields in the table and I am iterating through them all)

<%= parser['table'][i].desc %>

1 Answer 1

1

I assume you are using EJS as your template engine? If so then https://ejs.co/#docs offers the solution:

<%= Outputs the value into the template (HTML escaped)

<%- Outputs the unescaped value into the template

So you want to use this

<%- parser['table'][i].desc %>

to avoid escaping of HTML/XML.

Sign up to request clarification or add additional context in comments.

2 Comments

This is exactly this, I just started using EJS and was unaware of this and tried much more complex things in vain! Thank you very much sir, +1!
glad it worked; please don't forget to upvote and accept the answer if it helped you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.