Express: Explicitly render a string of HTML or markdown in Jade

Created on 28 Mar 2012  路  4Comments  路  Source: expressjs/express

Hey everyone,

I want to render some HTML in a Jade view which was passed through a variable.

It is currently rendering as escaped HTML and not plain HTML, how do I go about explicitly rendering it as plain HTML?
I understand it may be a bad security practice but what if it is plain markdown text that gets converted to HTML at render time?

// in the route
res.render('index', { title: 'Lorem Ipsum', article: '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>' });

// jade view
h1= title
#{article}

The current output:

<h1>Lorem Ipsum</h1>
&lt;p&gt;Lorem ipsum dolor sit amet, consectetur adipiscing elit.&lt;/p&gt;

I would like it to be rendered as:

<h1>Lorem Ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

Markdown scenario:

// in the route
res.render('index', { title: 'Lorem Ipsum', article: md('Lorem ipsum dolor sit amet, consectetur adipiscing elit.') });

I would like it to be rendered as:

<h1>Lorem Ipsum</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>

Most helpful comment

!{article}

All 4 comments

!{article}

Shweet, thanks man, how did you know? Where can I find more of the syntax?

In the jade readme.

On Wed, 28 Mar 2012 08:00:29 -0700, Andrew Quan [email protected] wrote:

Shweet, thanks man, how did you know? Where can I find more of the syntax?

Ah, figures, thanks again wereHamster.

Was this page helpful?
0 / 5 - 0 ratings