Skip to content

Instantly share code, notes, and snippets.

@jgwill
Created April 15, 2019 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgwill/7e32a94c66b4a541958ab834377554ab to your computer and use it in GitHub Desktop.
Save jgwill/7e32a94c66b4a541958ab834377554ab to your computer and use it in GitHub Desktop.
@stcgoal That we can use Markdown into Templates data that will be rendered as HTML
//import
var h = require('handlebars');
//@stcgoal That we can use Markdown into Templates data that will be rendered as HTML
h.registerHelper('markdown', require('helper-markdown'));
//-------------------------------------------
//@STCGoal Use Markdown in your Code to Render it as HTML
//Handlebars sources
var code = `
<div>
<h1>{{title}}</h1>
<p>{{description}}</p>
<hr>Using Markdown handlebars-helper<hr>
{{#markdown}}
# Title Something
---
* Points a
* Point b
{{/markdown}}
</div>
`;
//Data structure with values
var data = {
title : "Hello world Markdown",
description: "Hello world is a common Magna cillum consequat incididunt laboris nisi voluptate fugiat id voluptate incididunt.",
peoples:[{name:"Guillaume",note:"main scientist and artist"},{name:"Peter Pan",note:"ficticious caracter"}]
};
var template = h.compile(code);
console.log(template(data));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment