Search code examples
node.jspugkeystonejs

nodejs keystone : stop html entity replacing "<" with "&lt;"


Want to render page sections with html coming from the data base. Using keystone with default jade & mongo.

To test in my init (view.on('init', function(next) {) function i have

 locals.intro = "my intro<b>bolder 2</b>";

On my jade template source this gets rendered with the opening and closing angular brackets escaped :

  my intro&lt;b&gt;bolder 2&lt;/b&gt;

How do I stop this? Similarly for fields from the data base console.log shows the expected value, as expected like :

  </b>

but on the page its escaped.

NOTE : do not think its related to decodeURIComponent as don't want to decode on server, but want server to stop encoding before sending to browser, part of page render.


Solution

  • You can request Jade not to escape characters by using !

    // if intro = "<b> bolder </b>"
    
    != intro // will render as <b> bolder </b>
    

    However, be careful if the source of any of the unescaped content is untrusted (i.e. users) as this can lead to very bad things.