Code coverage report for lib/output/html.js

Statements: 100% (19 / 19)      Branches: 100% (10 / 10)      Functions: 100% (4 / 4)      Lines: 100% (19 / 19)      Ignored: none     

All files » lib/output/ » html.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60    25                     25 3 5 3   2                     25 19 19   19 3     19                         25 10 10 10 10 1   10    
'use strict';
 
var walk = require('../walk'),
  path = require('path'),
  hljs = require('highlight.js');
 
/**
 * Create a highlighter function that transforms strings of code
 * into strings of HTML with highlighting tags.
 *
 * @param {boolean} auto whether to automatically detect a language
 * @returns {Function} highlighter function
 */
function highlightString(auto) {
  return function (example) {
    if (auto) {
      return hljs.highlightAuto(example).value;
    }
    return hljs.highlight('js', example).value;
  };
}
 
/**
 * Highlights the contents of the `example` tag.
 * @name highlight
 * @param {Object} comment parsed comment
 * @param {Object} [options] options
 * @return {Object} comment with highlighted code
 */
function highlight(comment, options) {
  var hljsOptions = options.hljs || {};
  hljs.configure(hljsOptions);
 
  if (comment.examples) {
    comment.examples = comment.examples.map(highlightString(hljsOptions.highlightAuto));
  }
 
  return comment;
}
 
/**
 * Formats documentation as HTML.
 *
 * @param {Array<Object>} comments parsed comments
 * @param {Object} options Options that can customize the output
 * @param {string} [options.theme='documentation-theme-default'] Name of a module used for an HTML theme.
 * @param {Function} callback called with array of results as vinyl-fs objects
 * @returns {undefined} calls callback
 * @name html
 */
module.exports = function makeHTML(comments, options, callback) {
  options = options || {};
  comments = walk(comments, highlight, options);
  var theme = require('documentation-theme-default');
  if (options.theme) {
    theme = require(path.resolve(process.cwd(), options.theme));
  }
  theme(comments, options, callback);
};