-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from gormus/patch-1
Update markdown.js
- Loading branch information
Showing
1 changed file
with
16 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} |