Stachedown
Stachedown renders Mustache templates written in Markdown.
Installation
npm install stachedown
Usage
Stachedown can be used to render
HTML from Markdown-Mustache templates and inject
Mustache directly into Markdown without rendering the Makrdown.
Rendering HTML
var Stachedown = stachedown = ; var template = "{{a}} is *{{b}}*." data = a: 'Shrek' b: 'love'; stachedown;// => "<p>Shrek is <em>love</em>.</p>\n"
Injecting Mustache
var Stachedown = stachedown = ; var template = "{{a}} is *{{b}}*." data = a: 'Shrek' b: 'love'; stachedown;// => "Shrek is *love*."
Configuration
Stachedown requires mustache.js and marked. While it does not provided anything more than functions, Stachedown does expose its dependencies for their own configuration options.
var Stachedown = Marked = StachedownMarked Mustache = StachedownMustache;
Marked options can also be passed directly to the Stachedown constructor and will be used for each render with that Stachedown instance. See marked for more details.
var Stachedown = stachedown = ;
Stachedown can determine whether marked is configured asynchronously and adapt to compliment an asynchronous call.
stachedown;
Strict Templating
Suppose a template is rendered with an object literal as data using Mustache. Mustache ignores missing and undefined variables in templates.
Mustache;// => 'The must be visible.'
This output almost always is not ideal. Stachedown exposes two methods #renderStrict()
and #injectStrict()
to ensure variables exist when put into the template. They have the same function signatures as their #render()
and #inject()
counterparts.
stachedown;// throws Error
While strict templating is not a direct goal of Stachedown, I thought the use case was good enough to include it within this module as an option.
Contributing
Contributions are incredibly welcome as long as they are standardly applicable and pass the tests (or break bad ones). Tests are written in Mocha and assertions are done with the Node.js core assert
module.
# running tests npm run testnpm run test-spec # spec reporter
Follow me on Twitter for updates or just for the lolz and please check out my other repositories if I have earned it. I thank you for reading.