Šime Vidas Šime Vidas - 7 months ago 35
Javascript Question

Is it possible to include external files when using Jade’s :markdown filter?

I'm building an Express.js Node app and using Jade templates. Jade provides a

:markdown
filter which enables embedding Markdown code inside Jade:

h1 This is Jade
:markdown
## And this is Markdown
h3 Back in Jade


(Note: In order to use this filter you have to npm install a Markdown engine, e.g.
npm install marked --save
. You don't have to
require()
this module within your Express app, but it has to be installed.)

So, embedding Markdown within Jade works fine. However, I would like to keep my Markdown in separate files and include them in Jade templates dynamically. I've tried this and it does not work:

:markdown
include ../path/to/markdown/file.md


The
include
command is treated as source code instead of being interpreted as a command. Is it possible to inject Markdown from external files within the
:markdown
filter?

Please don't provide workarounds! I know how to work around this issue. I want to know if the
:markdown
filter is compatible with external Markdown files.

Answer

You can include markdown files using the :md filter modifier

eg.

html
  body
    include:md ../path/to/markdown/file.md

I found it by looking at the filtered include test: https://github.com/visionmedia/jade/blob/master/test/cases/include-filter.jade