josef
josef

Reputation: 255

parse html content in node.js

im trying to render a view with content from a database, my database contains html formated content and i want to keep this formatting, but when I try to render the content i get it as strings and not html, is there anyway i can parse this content and keep the formatting?

I don't want the tags to be displayed at the site.

view contact.jade

div.shareimg(style='background-image:#{document.Img}')
div#shareContent
h2.shareTag #{document.insightheader}
p.shareTag #{document.description}
b#TLDT.shareTag #{document.TLDR}
p.shareTag #{document.MoreInfo}

node

app.get('/share/:id', function(req, res) {
    var db = req.db_login;
    console.log(req.params.id)
    db.collection('insights').findById(req.params.id, function(error, document) {
        console.log(document)
        if (error || !document) {
            res.render('error', {});
        } else {
            res.render('contact', { document : document });
        }
    })
});

console.log

{
    _id: 544cf40e9f697dc430ccd2dd,
    Img: 'url(http://localhost:3000/images/previewImg.svg)',
    insightheader: '<p>dsada</p>',
    description: '<p>dsa</p><p>dsa</p><p>das</p><p>dasdd</p>',
    TLDR: '<strong>TLDR;dasdas</strong>',
    MoreInfo: '<p>dsadsa</p>',
    date: '\'1414329358033\''
}

result

enter image description here

Upvotes: 0

Views: 120

Answers (1)

mscdex
mscdex

Reputation: 106736

With Jade you can do unescaped interpolation by using !{var} instead of #{var}.

Upvotes: 2

Related Questions