Code coverage report for master/plugins/markdown.js

Statements: 94.29% (33 / 35)      Branches: 84% (21 / 25)      Functions: 100% (6 / 6)      Lines: 94.29% (33 / 35)      Ignored: none     

All files » master/plugins/ » 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 90                1   1 1                   1 1 1 1   1 10     10 1     10                 1 16 128 104     24 9   15 10 8 8 8 8     5 5           1       1     1 8 8       1           3      
/**
 * @overview Translate doclet descriptions from MarkDown into HTML.
 * @module plugins/markdown
 * @author Michael Mathews <micmath@gmail.com>
 * @author Ben Blank <ben.blank@gmail.com>
 */
'use strict';
 
var env = require('jsdoc/env');
 
var config = env.conf.markdown || {};
var defaultTags = [
    'author',
    'classdesc',
    'description',
    'exceptions',
    'params',
    'properties',
    'returns',
    'see'
];
var hasOwnProp = Object.prototype.hasOwnProperty;
var parse = require('jsdoc/util/markdown').getParser();
var tags = [];
var excludeTags = [];
 
function shouldProcessString(tagName, text) {
    var shouldProcess = true;
 
    // we only want to process `@author` and `@see` tags that contain Markdown links
    if ( (tagName === 'author' || tagName === 'see') && text.indexOf('[') === -1 ) {
        shouldProcess = false;
    }
 
    return shouldProcess;
}
 
/**
 * Process the markdown source in a doclet. The properties that should be
 * processed are configurable, but always include "classdesc", "description",
 * "params", "properties", and "returns".  Handled properties can be bare
 * strings, objects, or arrays of objects.
 */
function process(doclet) {
    tags.forEach(function(tag) {
        if ( !hasOwnProp.call(doclet, tag) ) {
            return;
        }
 
        if (typeof doclet[tag] === 'string' && shouldProcessString(tag, doclet[tag]) ) {
            doclet[tag] = parse(doclet[tag]);
        }
        else if ( Array.isArray(doclet[tag]) ) {
            doclet[tag].forEach(function(value, index, original) {
                var inner = {};
                inner[tag] = value;
                process(inner);
                original[index] = inner[tag];
            });
        }
        else Eif (doclet[tag]) {
            process(doclet[tag]);
        }
    });
}
 
// set up the list of "tags" (properties) to process
Iif (config.tags) {
    tags = config.tags.slice();
}
// set up the list of default tags to exclude from processing
Iif (config.excludeTags) {
    excludeTags = config.excludeTags.slice();
}
defaultTags.forEach(function(tag) {
    Eif (excludeTags.indexOf(tag) === -1 && tags.indexOf(tag) === -1) {
        tags.push(tag);
    }
});
 
exports.handlers = {
    /**
     * Translate markdown syntax in a new doclet's description into HTML. Is run
     * by JSDoc 3 whenever a "newDoclet" event fires.
     */
    newDoclet: function(e) {
        process(e.doclet);
    }
};