Skip to content

Commit

Permalink
Merge pull request foundation#149 from gormus/patch-1
Browse files Browse the repository at this point in the history
Update markdown.js
  • Loading branch information
gakimball authored Jan 24, 2018
2 parents 2930be5 + 2db6069 commit 6a1ab7a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions helpers/markdown.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
var hljs = require('highlight.js');
var marked = require('marked');

/**
* Handlebars block helper that converts Markdown to HTML.
* The code blocks in the markdown are rendered with the syntax highlighting.
* @param {object} options - Handlebars object.
* @example
* {{#markdown}}Welcome to [zombo.com](http://zombo.com){{/markdown}}
* @returns The Markdown inside the helper, converted to HTML.
*/
module.exports = function(options) {
return marked(options.fn(this));
}
module.exports = function(options) {
var renderer = new marked.Renderer();

renderer.code = function(code, language) {
if (typeof language === 'undefined') language = 'html';

var renderedCode = hljs.highlight(language, code).value;
var output = `<div class="code-example"><pre><code class="${language}">${renderedCode}</code></pre></div>`;

return output;
};

return marked(options.fn(this), { renderer });
}

0 comments on commit 6a1ab7a

Please sign in to comment.