Package Exports
- helper-markdown
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (helper-markdown) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
helper-markdown

Markdown template helper. Uses remarkable to render markdown in templates. Should work with Handlebars, Lo-Dash or any template engine that supports helper functions.
- Install
- API
- Usage examples
- Register the helper
- Related projects
- Running tests
- Contributing
- Author
- License
(TOC generated by verb using markdown-toc)
Install
Install with npm:
$ npm i helper-markdown --saveAPI
var markdown = require('helper');Returns a function that returns the helper, allowing an options object to be passed:
var hbs = require('handlebars');
hbs.registerHelper('markdown', markdown([options]));Example
Pass a custom highlight function for syntax highlighting to [Remarkable][], the markdown renderer:
var hljs = require('highlight.js');
var markdown = require('helper-markdown');
function highlight(code, lang) {
try {
try {
return hljs.highlight(lang, code).value;
} catch (err) {
if (!/Unknown language/i.test(err.message)) {
throw err;
}
return hljs.highlightAuto(code).value;
}
} catch (err) {
return code;
}
}
hbs.registerHelper('markdown', markdown({
highlight: highlight
}));Usage examples
With Handlebars:
<div>
{{#markdown}}
# Heading
> this is markdown
foo bar baz
{{/markdown}}
</div>Results in:
<h1>Heading</h1>
<blockquote>
<p>this is markdown</p>
</blockquote>
<p>foo bar baz</p>Register the helper
This should work with any engine, here are a few examples
templates
The templates library supports any templates engine supported by consolidate. To register the helper with templates:
var templates = require('templates');
var app = templates();
app.helper('markdown', require('helper-markdown'));assemble
To register the helper for use with assemble v0.6.0 and higher:
assemble.helper('markdown', require('helper-markdown'));verb
Register the helper for use with verb:
var verb = require('verb');
verb.helper('markdown', require('helper-markdown'));handlebars
To register the helper with handlebars:
var handlebars = require('handlebars');
handlebars.registerHelper('markdown', require('helper-markdown'));lodash
To register the helper with [Lo-Dash][] or underscore:
var markdown = require('helper-markdown');
// as a mixin
_.mixin({markdown: markdown});
_.template('<%= _.markdown("# heading") %>', {});
//=> '<h1>heading</h1>\n'
// passed on the context
_.template('<%= markdown("# heading") %>', {markdown: markdown});
//=> '<h1>heading</h1>\n'
// as an import
var settings = {imports: {markdown: markdown}};
_.template('<%= markdown("# heading") %>', {}, settings);
//=> '<h1>heading</h1>\n'Related projects
- assemble: Assemble is a powerful, extendable and easy to use static site generator for node.js. Used… more | homepage
- handlebars: Handlebars provides the power necessary to let you build semantic templates effectively with no frustration | homepage
- lodash: Lodash modular utilities. | homepage
- template: Render templates using any engine. Supports, layouts, pages, partials and custom template types. Use template… more | homepage
- underscore: JavaScript's functional programming helper library. | homepage
- verb: Documentation generator for GitHub projects. Verb is extremely powerful, easy to use, and is used… more | homepage
Running tests
Install dev dependencies:
$ npm i -d && npm testContributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
Author
Jon Schlinkert
License
Copyright © 2016 Jon Schlinkert Released under the MIT license.
This file was generated by verb on January 15, 2016.