mirror of
https://github.com/jsdoc/jsdoc.git
synced 2025-12-08 19:46:11 +00:00
add exception/throws to default tag list for Markdown plugin (#736)
Plus some test refactoring. Thanks to @otakustay for suggesting this change.
This commit is contained in:
parent
8f1d892fbf
commit
36065d22e8
@ -1,4 +1,3 @@
|
|||||||
/*global env: true */
|
|
||||||
/**
|
/**
|
||||||
* @overview Translate doclet descriptions from MarkDown into HTML.
|
* @overview Translate doclet descriptions from MarkDown into HTML.
|
||||||
* @module plugins/markdown
|
* @module plugins/markdown
|
||||||
@ -7,8 +6,16 @@
|
|||||||
*/
|
*/
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var conf = env.conf.markdown;
|
var config = global.env.conf.markdown || {};
|
||||||
var defaultTags = [ 'classdesc', 'description', 'params', 'properties', 'returns', 'see'];
|
var defaultTags = [
|
||||||
|
'classdesc',
|
||||||
|
'description',
|
||||||
|
'exceptions',
|
||||||
|
'params',
|
||||||
|
'properties',
|
||||||
|
'returns',
|
||||||
|
'see'
|
||||||
|
];
|
||||||
var hasOwnProp = Object.prototype.hasOwnProperty;
|
var hasOwnProp = Object.prototype.hasOwnProperty;
|
||||||
var parse = require('jsdoc/util/markdown').getParser();
|
var parse = require('jsdoc/util/markdown').getParser();
|
||||||
var tags = [];
|
var tags = [];
|
||||||
@ -58,12 +65,12 @@ function process(doclet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set up the list of "tags" (properties) to process
|
// set up the list of "tags" (properties) to process
|
||||||
if (conf && conf.tags) {
|
if (config.tags) {
|
||||||
tags = conf.tags.slice();
|
tags = config.tags.slice();
|
||||||
}
|
}
|
||||||
// set up the list of default tags to exclude from processing
|
// set up the list of default tags to exclude from processing
|
||||||
if (conf && conf.excludeTags) {
|
if (config.excludeTags) {
|
||||||
excludeTags = conf.excludeTags.slice();
|
excludeTags = config.excludeTags.slice();
|
||||||
}
|
}
|
||||||
defaultTags.forEach(function(tag) {
|
defaultTags.forEach(function(tag) {
|
||||||
if (excludeTags.indexOf(tag) === -1 && tags.indexOf(tag) === -1) {
|
if (excludeTags.indexOf(tag) === -1 && tags.indexOf(tag) === -1) {
|
||||||
|
|||||||
24
plugins/test/fixtures/markdown.js
vendored
Normal file
24
plugins/test/fixtures/markdown.js
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see [Nowhere](http://nowhere.com)
|
||||||
|
*/
|
||||||
|
function foo() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see AnObject#myProperty
|
||||||
|
*/
|
||||||
|
function bar() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @classdesc My class.
|
||||||
|
* @description My class.
|
||||||
|
* @exception {Error} Some error.
|
||||||
|
* @param {string} myParam - My parameter.
|
||||||
|
* @property {string} value - Value of myParam.
|
||||||
|
* @return {MyClass} Class instance.
|
||||||
|
* @see [Example Inc.](http://example.com)
|
||||||
|
*/
|
||||||
|
function MyClass(myParam) {
|
||||||
|
this.value = myParam;
|
||||||
|
}
|
||||||
11
plugins/test/fixtures/seetag-markdown.js
vendored
11
plugins/test/fixtures/seetag-markdown.js
vendored
@ -1,11 +0,0 @@
|
|||||||
/**
|
|
||||||
* @see [Nowhere](http://nowhere.com)
|
|
||||||
*/
|
|
||||||
function foo() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see AnObject#myProperty
|
|
||||||
*/
|
|
||||||
function bar() {
|
|
||||||
}
|
|
||||||
@ -1,29 +1,48 @@
|
|||||||
/*global describe: true, env: true, expect: true, it: true, jasmine: true */
|
'use strict';
|
||||||
|
|
||||||
var path = require('jsdoc/path');
|
var path = require('jsdoc/path');
|
||||||
|
|
||||||
describe("markdown plugin", function() {
|
describe('markdown plugin', function() {
|
||||||
//TODO
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("markdown see tag support", function() {
|
|
||||||
var pluginPath = 'plugins/markdown';
|
var pluginPath = 'plugins/markdown';
|
||||||
var pluginPathResolved = path.join(env.dirname, pluginPath);
|
var pluginPathResolved = path.join(global.env.dirname, pluginPath);
|
||||||
var plugin = require(pluginPathResolved);
|
var plugin = require(pluginPathResolved);
|
||||||
|
|
||||||
var docSet = jasmine.getDocSetFromFile('plugins/test/fixtures/seetag-markdown.js');
|
var docSet = jasmine.getDocSetFromFile('plugins/test/fixtures/markdown.js');
|
||||||
var foo = docSet.getByLongname('foo')[0];
|
|
||||||
var bar = docSet.getByLongname('bar')[0];
|
|
||||||
|
|
||||||
it ('should parse @see tags containing links', function() {
|
// TODO: more tests; refactor the plugin so multiple settings can be tested
|
||||||
plugin.handlers.newDoclet({doclet:foo});
|
|
||||||
expect(typeof foo).toEqual('object');
|
it('should process the correct tags by default', function() {
|
||||||
expect(foo.see[0]).toEqual('<p><a href="http://nowhere.com">Nowhere</a></p>');
|
var myClass = docSet.getByLongname('MyClass')[0];
|
||||||
|
|
||||||
|
plugin.handlers.newDoclet({ doclet: myClass });
|
||||||
|
[
|
||||||
|
myClass.classdesc,
|
||||||
|
myClass.description,
|
||||||
|
myClass.exceptions[0].description,
|
||||||
|
myClass.params[0].description,
|
||||||
|
myClass.properties[0].description,
|
||||||
|
myClass.returns[0].description,
|
||||||
|
myClass.see
|
||||||
|
].forEach(function(value) {
|
||||||
|
// if we processed the value, it should be wrapped in a <p> tag
|
||||||
|
expect( /^<p>(?:.+)<\/p>$/.test(value) ).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('should not parse @see tags that do not contain links', function() {
|
describe('@see tag support', function() {
|
||||||
plugin.handlers.newDoclet({doclet:bar});
|
var foo = docSet.getByLongname('foo')[0];
|
||||||
expect(typeof bar).toEqual('object');
|
var bar = docSet.getByLongname('bar')[0];
|
||||||
expect(bar.see[0]).toEqual('AnObject#myProperty');
|
|
||||||
|
it('should parse @see tags containing links', function() {
|
||||||
|
plugin.handlers.newDoclet({ doclet: foo });
|
||||||
|
expect(typeof foo).toEqual('object');
|
||||||
|
expect(foo.see[0]).toEqual('<p><a href="http://nowhere.com">Nowhere</a></p>');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not parse @see tags that do not contain links', function() {
|
||||||
|
plugin.handlers.newDoclet({ doclet: bar });
|
||||||
|
expect(typeof bar).toEqual('object');
|
||||||
|
expect(bar.see[0]).toEqual('AnObject#myProperty');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user