New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

stachedown

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

stachedown

you got mustache in my markdown

latest
Source
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

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 = require("stachedown"),
	stachedown = Stachedown();

var template = "{{a}} is *{{b}}*.",
	data = {a: 'Shrek', b: 'love'};

stachedown.render(template, data);
// => "<p>Shrek is <em>love</em>.</p>\n"

Injecting Mustache

var Stachedown = require("stachedown"),
	stachedown = Stachedown();

var template = "{{a}} is *{{b}}*.",
	data = {a: 'Shrek', b: 'love'};

stachedown.inject(template, data);
// => "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 = require("stachedown"),
	Marked = Stachedown.Marked,
	Mustache = Stachedown.Mustache;

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 = require("stachedown"),
	stachedown = Stachedown({marked options});

Stachedown can determine whether marked is configured asynchronously and adapt to compliment an asynchronous call.

stachedown.render(template, data, function(error, html) {
	// Note: This only works for #render().
	// Stachedown#inject() is always synchronous.
});

Strict Templating

Suppose a template is rendered with an object literal as data using Mustache. Mustache ignores missing and undefined variables in templates.

Mustache.render('The {{important_thing}} must be visible.', {});
// => '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.renderStrict('The {{important_thing}} must be visible.', {});
// 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 test
npm 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.

Keywords

template

FAQs

Package last updated on 23 Aug 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts