Node Express markdown loop

Problem

How do I loop over an object and output markdown as part of the loop in my jade template?

Here is my template file

block content
  section.content
    h1= title
    p Welcome to #{title}
    ul
      each post in posts
        li!= :markdown
          post

Here is an example posts object

{
    "post1": "#Hey\nHow are you?",
    "post2": "#Hello\nworld"
}

But I don't seem to be able to get the markdown to work inside of the loop, I've read over the documentation and tried Googleing but don't seem to be able to find anything that doesn't require loading another library for markdown in the view when Jade already has it.

Problem courtesy of: Dave Mackintosh

Solution

I did some more research on the issue and as far as I understand it it is because:

:markdown

Is compiled at a different time to evaluated scripts such as my != post

The fix was:

Since I could never get :markdown to compile after my post object, I injected the node-markdown module into my views like this.

var MarkDown = require('node-markdown').MarkDown;
res.render('blog', {
    "title": name,
    "md"   : Markdown,
});

And in my view I used this

each post in posts
  li!= md(post)

And it all appeared to work, I've left the title var out of my example because it wasn't really part of the fix, just asthetic.

Solution courtesy of: Dave Mackintosh

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.