Giter Site home page Giter Site logo

romakita / helper-markdown Goto Github PK

View Code? Open in Web Editor NEW

This project forked from helpers/helper-markdown

0.0 1.0 0.0 40 KB

Markdown template helper. Uses remarkable to render markdown in templates. Should work with Handlebars, Lo-Dash or any template engine that supports helper functions.

License: MIT License

JavaScript 100.00%

helper-markdown's Introduction

helper-markdown NPM version NPM monthly downloads NPM total downloads Linux Build Status

Markdown template helper. Uses remarkable to render markdown in templates. Should work with Handlebars, Lo-Dash or any template engine that supports helper functions.

(TOC generated by verb using markdown-toc)

Install

Install with npm:

$ npm install --save helper-markdown

API

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'

About

Related projects

  • 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

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Contributors

Commits Contributor
14 jonschlinkert
5 doowb
2 almeidap

Building docs

(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:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

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:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on July 08, 2017.

helper-markdown's People

Contributors

jonschlinkert avatar doowb avatar almeidap avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.