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
}));
With Handlebars:
Results in:
<h1>Heading</h1>
<blockquote>
<p>this is markdown</p>
</blockquote>
<p>foo bar baz</p>
This should work with any engine, here are a few examples
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'));
To register the helper for use with [assemble][] v0.6.0 and higher:
assemble.helper('markdown', require('helper-markdown'));
Register the helper for use with [verb][]:
var verb = require('verb');
verb.helper('markdown', require('helper-markdown'));
To register the helper with [handlebars][]:
var handlebars = require('handlebars');
handlebars.registerHelper('markdown', require('helper-markdown'));
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'