Passed
Push — master ( 22873c...be0969 )
by Björn
02:06
created

lib/handlebars/markdown.js (1 issue)

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
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

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 (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
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