Using filters in Jade
Jade filters are powerful features which enable the users to use different markups inside Jade templates. Their primary use is to make templates even more succinct by enabling the user to use the appropriate tool for a particular section of the template.
In this recipe, we're going to use Jade filters to embed markdown inside our template and explain how filters work.
Getting ready
The client-side version of Jade https://github.com/visionmedia/jade is found in the jade.js
file and does not support markdown filters out of the box. To add support for markdown we need edit this file and find the line that starts defining the markdown
filter:
markdown: function(str){ var md; // support markdown / discount try { …. } str = str.replace(/\\n/g, '\n'); return md.parse(str).replace(/\n/g, '\\n').replace(/'/g,'''); },
And then replace it with the following function:
markdown: function(str){ str = str.replace(/\\n/g, '\n'); return markdown...