Hello,

I have been trying to learn Node with Express for about a week now. So far I got the basics of how to build MVC on top of it, and using JavaScript proved easier and cleaner than I would have ever gotten with another server language (except Python, maybe). But let's get into one of my first problems and one of a few I couldn't solve myself.

I'm using the Jade templating engine and I love it. I love how simple it is to input Markdown into the template. You just say :markdown and it's there!

But then I got into a problem. It's all easy to parse and print Markdown, however how am I supposed to display a blog post, for example, that's been stored as Markdown text in the database, on screen? I tried:

each entry in posts
    h1 #{entry.title}
    :markdown
        #{entry.text}
    div#post-footer
        #{entry.date}

But the # gets parsed as a Markdown header, not a Jade directive. How do I make it so I can display Markdown properly?

有帮助吗?

解决方案

var md = require('marked');

res.render('template', {md: md, markdownContent: markdownContent};

then inside the template use div!= md(markdownContent);

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top