1

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?

1 Answer 1

4
var md = require('marked');

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

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

Sign up to request clarification or add additional context in comments.

5 Comments

Well, at least it prints out now, but it prints the = as well. Any idea?
Sorry my jade is a bit rusty I've been neckdeep in APIs for a while, try removing the = I thought it was necessary but it may not be inside the filter
Without the = it's just like I tried in my question. Won't work either.
The only thing that would be left then is to pass in the function to the view. I'll update my answer to reflect the needed code
Yeah, that's what I thought I should do then. Parse Markdown before the template. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.