Code coverage report for lib/markdown.js

Statements: 95.74% (45 / 47)      Branches: 82.61% (19 / 23)      Functions: 100% (6 / 6)      Lines: 95.74% (45 / 47)      Ignored: none     

All files » lib/ » markdown.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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89                      1 1 1   1 1   1   34 34 34 34   1 4 4 4 4 4 14   4     34 34 22 2 4 4 4   4   20 20 64 64 64       64     64             34   34   34 1   33     34 34 34   34   34 34       1      
/*
 * grunt-markdown
 * https://github.com/treasonx/grunt-markdown
 *
 * Copyright (c) 2012 James Morrin
 * Licensed under the MIT license.
 */
 
'use strict';
 
// external libs
var markdown = require('marked');
var hljs = require('highlight.js');
var _ = require('lodash');
 
exports.init = function(grunt) {
  var exports = {};
 
  exports.markdown = function(src, options, template) {
 
    var html = null;
    var templateContext = null;
    var codeLines = options.codeLines;
    var shouldWrap = codeLines && codeLines.before && codeLines.after;
 
    function wrapLines(code) {
      var out = [];
      var before = codeLines.before;
      var after = codeLines.after;
      code = code.split('\n');
      code.forEach(function(line) {
        out.push(before+line+after);
        });
      return out.join('\n');
    }
 
    Eif(options.markdownOptions && typeof options.markdownOptions === 'object'){
      if(typeof options.markdownOptions.highlight === 'string') {
        if(options.markdownOptions.highlight === 'auto') {
          options.markdownOptions.highlight = function(code) {
            var out = hljs.highlightAuto(code).value;
            Eif(shouldWrap) {
              out = wrapLines(out);
            }
            return out;
          };
        } else Eif (options.markdownOptions.highlight === 'manual') {
          options.markdownOptions.highlight = function(code, lang) {
            var out = code;
            try {
              out = hljs.highlight(lang, code).value;
            } catch(e) {
              out = hljs.highlightAuto(code).value;
            }
            Iif(shouldWrap) {
              out = wrapLines(out);
            }
            return out;
          };
        }
 
      }
    }
 
    markdown.setOptions(options.markdownOptions);
 
    grunt.verbose.write('Marking down...');
 
    if(_.isFunction(options.templateContext)) {
      templateContext = options.templateContext();
    } else {
      templateContext = options.templateContext;
    }
 
    src = options.preCompile(src, templateContext) || src;
    html = markdown(src);
    html = options.postCompile(html, templateContext) || html;
 
    templateContext.content = html;
 
    src = _.template(template, templateContext);
    return src;
 
  };
 
  return exports;
};