How can I render markdown in express.js jade template?

trnc picture trnc · Jun 15, 2011 · Viewed 12.9k times · Source

I use the express js framework. I have a markdownified string from the database and want to render it as HTML in my jade template. I installed node-markdown and want to render it this way:

app.js

var md = require("node-markdown").Markdown;

template.jade

- each note in todo.notes
  div= md(note.string)

However, it doesn't print out anything... any advice at this?

Thanks!

EDIT: solved it myself, just forgot to get the md variable into my view...

Answer

Josh picture Josh · Jun 16, 2011

There is the concept of 'filters' that expose a 'compiler' or 'filter' visitor to a portion of the jade template.

Check out: https://github.com/visionmedia/jade

filters

:sass must have sass.js installed

:less must have less.js installed

:markdown must have markdown-js installed or node-discount

:cdata

:coffeescript must have coffee-script installed

You use it via this syntax in a template: http://jade-lang.com/reference/filters/