0
votes

I have a document which contains some metadata in the form of small markdown snippets.
Inside of a layout, I want to grab them, render them from markdown to HTML, and then print out the results. (I’m using DocPad’s default template engine, “Eco”.)

Is this possible?

2
Its hard to understand what you are trying to do. Docpad will automatically render markdown as html (well - if you have the docpad plugin "docpad-plugin-marked" installed). I would normally think of markdown as the default "template" engine - Steve Mc

2 Answers

0
votes

The following assumes you are using marked as your Markdown engine. If you are using RoboSkirt or something else, you can do something similar, just adapt to use their module instead.

First, make sure you have the marked node module in your top level project:

npm install --save marked 

Then add a helper function to your docpad.coffee that makes the marked function available in templates:

docpadConfig = {
    templateData:
        # Specify some site properties
        marked: require('marked')
}

Now you can use this in your .eco files:

<div>
    <%- @marked(@document.someMetaProperty) %>
</div>
0
votes

Another way to Erv's answer is to use the Docpad Api which let's you pass the text through its render workflow (this way you can use other installed template engines too)

var renderOpts = {
    text: 'here is some **markdown**',
    filename:'markdown',
    renderSingleExtensions:true
};
docpadInstance.action('render', renderOpts, function(err,result){
    console.log(result);
});

source for above snippet: http://docpad.org/docs/api#rendering-individual-files