Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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...

like image 362
trnc Avatar asked Jun 15 '11 13:06

trnc


1 Answers

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/

like image 68
Josh Avatar answered Oct 25 '22 03:10

Josh