Markdown template helper. Uses remarkable to render markdown in templates. Should work with Handlebars, Lo-Dash or any template engine that supports helper functions.
npm install 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
* templates
* assemble
* verb
* handlebars
* lodash
- About
_(TOC generated by verb using markdown-toc)_
Install with npm:
``sh`
$ npm install --save helper-markdown
`js`
var markdown = require('helper');
Returns a function that returns the helper, allowing an options object to be passed:
`js`
var hbs = require('handlebars');
hbs.registerHelper('markdown', markdown([options]));
Example
Pass a custom highlight function for syntax highlighting to [Remarkable][], the markdown renderer:
`js
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:
` > this is markdown foo bar bazhandlebars`
{{#markdown}}Heading
{{/markdown}}
Results in:
` this is markdown foo bar bazhtml`Heading
> 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:
`js
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:
`js`
assemble.helper('markdown', require('helper-markdown'));
Register the helper for use with verb:
`js`
var verb = require('verb');
verb.helper('markdown', require('helper-markdown'));
To register the helper with handlebars:
`js`
var handlebars = require('handlebars');
handlebars.registerHelper('markdown', require('helper-markdown'));
To register the helper with [Lo-Dash][] or underscore:
`js
var markdown = require('helper-markdown');
// as a mixin
_.mixin({markdown: markdown});
_.template('<%= _.markdown("# heading") %>', {});
//=> '
// passed on the context
_.template('<%= markdown("# heading") %>', {markdown: markdown});
//=> '
// as an import
var settings = {imports: {markdown: markdown}};
_.template('<%= markdown("# heading") %>', {}, settings);
//=> '
About
$3
* assemble: Get the rocks out of your socks! Assemble makes you fast at creating web projects… 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
$3
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
$3
| Commits | Contributor |
| --- | --- |
| 14 | jonschlinkert |
| 5 | doowb |
| 2 | almeidap |
$3
_(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)_
To generate the readme, run the following command:
`sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
`$3
Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:
`sh
$ npm install && npm test
``Jon Schlinkert
* github/jonschlinkert
* twitter/jonschlinkert
Copyright © 2017, Jon Schlinkert.
Released under the MIT License.
*
_This file was generated by verb-generate-readme, v0.6.0, on July 08, 2017._