I have been using the Express web framework for Node.JS, and have been using the markdown parser chjj/marked in order to parse markdown into HTML. I have also been able to render this markdown using Express. I use EJS templates in my Express projects typically and what I would like to be able to do is use EJS with markdown.
Ideally I would like to be able to use the compile-time includes that are normally used in EJS, an example of which is shown here:
<% include header.html %>
<h3>User List -- Located in users.html</h3>
<ul id="users">
<% users.forEach(function(user){ %>
<li><%= user.name %> -- <%= user.email %></li>
<% }) %>
</ul>
<% include footer.html %>
It would be nice if I could include markdown files as well within my EJS templates with something like the following:
<% include markdown-file.md %>
It would also be nice to be able to use the EJS syntax within markdown or provide some way of accessing the variables within the markdown. Is anything like this possible? If not, what would be the easiest way for me to use markdown for my content in an EJS template?
EDIT 5/19/13: I have really wanted to do something like this for use in my own projects so I had to give it a go at combining markdown with EJS. Take a look at my module on GitHub called markedejs if you are interested in this as well, the README explains what I've done pretty well. This module uses the marked in order to parse markdown into HTML, unescapes it, and passes the HTML template to EJS for final rendering. All the EJS syntax works within the markdown, and including an HTML templates within markdown templates is working as well. You can make markdown templates looking like the following:
<nop><% include header.html %></nop>
<%= site.title %>
=======================
<%= site.description %>
This project was created by <%= author.name %>. My website is
located at the url [<%= author.url %>]().
## <%= header %>

Hey <%= user.name %>! This is a test template for the `markedejs` module. We
can use markdown and EJS together for some pretty awesome results.
### The Classic EJS Supplies List
<ul>
<% for (var i = 0; i < supplies.length; i++) { %>
<li><%= supplies[i] %></li>
<% } %>
</ul>
### Your User Data
I like using markdown lists a whole lot better when I can.
- **Username:** <%= user.username %>
- **Name:** <%= user.name %>
- **Stars:** <%= user.stars %>
We can do some conditionals as well. You will only see the footer below this
paragraph if you pass in `true` for the `showFooter` flag.
<% if (showFooter !== undefined && showFooter === true) { %>
<%= footer %>
<% } %>
<nop><% include footer.html %></nop>
- The
<nop>tags are removed bymarkedejsand are included in the markdown template so that<p>tags are not added around the content ofheader.htmlandfooter.html.
However, this is not quite doing what I originally wanted yet, I would like to be able to include markdown templates within both other HTML templates and other markdown templates. Currently I can only include HTML templates within my markdown templates. Still hoping anyone might have a better idea about how I can make EJS includes work with markdown files?