Skip to content Skip to sidebar Skip to footer

EJS Rendering HTML

I've got a simple blog app on Express and MongoDB, using EJS to render my data. The problem I have is I want this to be styled like a paragraph:

Solution 1:

To be honest, I had the similar issue a week ago Mission was to disable javascript. I did that with sanitizer. I sanitized user info before inserting in MongoDB. So recommend you to do that with sanitize-html striptags. Those packages are in npm you can download the package. I hope you will solve the problem.

var striptags = require('striptags');    
    YourCollectionName.find({}, function (err, obj) {
      if (err) {
        //handle or throw error
      }

  // For all the documents, remove html tags and save
  obj.forEach(function(ob){
    ob.body= striptags(ob.body);
    ob.save();
  });
});

Solution 2:

I've got it:

<div class="show-post__content">

   <%- post.body %>

 </div>

Is the answer.

Thanks if you had a look!


Post a Comment for "EJS Rendering HTML"