1 | 1 | var handlebars = require('handlebars'); |
|
2 | 1 | var hljs = require('highlight.js'); |
|
3 | 1 | var $markdown = require('../vendor/markdown-it'); |
|
4 | |||
5 | |||
6 | function highlightCode(code, language) { |
||
7 | 2 | if (typeof language === 'undefined') language = 'html'; |
|
0 ignored issues
–
show
|
|||
8 | |||
9 | var renderedCode = hljs.highlight(language, code).value; |
||
10 | var output = `<div class="code-example"><pre><code class="${language}">${renderedCode}</code></pre></div>`; |
||
11 | |||
12 | return output; |
||
13 | }; |
||
14 | |||
15 | function markdown(options) { |
||
16 | |||
17 | 2 | return $markdown.render(options.fn(this)); |
|
18 | } |
||
19 | |||
20 | |||
21 | /** |
||
22 | * Handlebars block helper that converts Markdown to HTML. |
||
23 | * The code blocks in the markdown are rendered with the syntax highlighting. |
||
24 | * @param {object} options - Handlebars object. |
||
25 | * @example |
||
26 | * {{#markdown}}Welcome to [zombo.com](http://zombo.com){{/markdown}} |
||
27 | * @returns The Markdown inside the helper, converted to HTML. |
||
28 | */ |
||
29 | 1 | handlebars.registerHelper('markdown', markdown); |
|
30 | module.exports = markdown; |
||
31 |
Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.
Consider:
If you or someone else later decides to put another statement in, only the first statement will be executed.
In this case the statement
b = 42
will always be executed, while the logging statement will be executed conditionally.ensures that the proper code will be executed conditionally no matter how many statements are added or removed.