From 427a46177da8fea42d15c8b7d5a771c8fac631bd Mon Sep 17 00:00:00 2001 From: phasmal Date: Thu, 3 Jan 2013 11:43:46 +1100 Subject: [PATCH] Added support for @see tag in markdown plugin, including adding 'see' to default list and fixing recursion into Arrays --- plugins/markdown.js | 21 ++++++++++++++------- plugins/test/fixtures/seetag-markdown.js | 12 ++++++++++++ plugins/test/specs/markdown.js | 21 ++++++++++++++++++++- 3 files changed, 46 insertions(+), 8 deletions(-) create mode 100644 plugins/test/fixtures/seetag-markdown.js diff --git a/plugins/markdown.js b/plugins/markdown.js index a6ad08ac..cf594552 100644 --- a/plugins/markdown.js +++ b/plugins/markdown.js @@ -5,9 +5,8 @@ * @author Michael Mathews * @author Ben Blank */ - var conf = env.conf.markdown; -var defaultTags = [ "classdesc", "description", "params", "properties", "returns" ]; +var defaultTags = [ "classdesc", "description", "params", "properties", "returns", "see"]; var parse = require('jsdoc/util/markdown').getParser(); var tags; @@ -22,12 +21,20 @@ function process(doclet) { if (!doclet.hasOwnProperty(tag)) { return; } - - if (typeof doclet[tag] === "string") { + + if (typeof doclet[tag] === "string" + && (tag != 'see' + // treat '@see' specially, since we only want to process @see text that contains links + || (tag == 'see' && doclet[tag].indexOf('[') != -1))) { doclet[tag] = parse(doclet[tag]); } else if (doclet[tag] instanceof Array) { - doclet[tag].forEach(process); - } else if (doclet[tag]) { + doclet[tag].forEach(function(value, index, original){ + var inner = {} + inner[tag] = value + process(inner) + original[index] = inner[tag] + }); + } else if (doclet[tag]) { process(doclet[tag]); } }); @@ -54,4 +61,4 @@ exports.handlers = { newDoclet: function(e) { process(e.doclet); } -}; \ No newline at end of file +}; diff --git a/plugins/test/fixtures/seetag-markdown.js b/plugins/test/fixtures/seetag-markdown.js new file mode 100644 index 00000000..57137616 --- /dev/null +++ b/plugins/test/fixtures/seetag-markdown.js @@ -0,0 +1,12 @@ +/** +* @see [Nowhere](http://nowhere.com) +*/ +function foo() { +} + +/** +* @see AnObject#myProperty +*/ +function bar() { +} + diff --git a/plugins/test/specs/markdown.js b/plugins/test/specs/markdown.js index c7c6db8e..13bb0ceb 100644 --- a/plugins/test/specs/markdown.js +++ b/plugins/test/specs/markdown.js @@ -1,3 +1,22 @@ describe("markdown plugin", function() { - // TODO + //TODO +}); + +describe("markdown see tag support", function() { + var plugin = require('plugins/markdown'), + docSet = jasmine.getDocSetFromFile('plugins/test/fixtures/seetag-markdown.js'), + foo = docSet.getByLongname('foo')[0], + bar = docSet.getByLongname('bar')[0]; + + it ('should parse @see tags containing links', function() { + plugin.handlers.newDoclet({doclet:foo}); + expect(typeof foo).toEqual('object'); + expect(foo.see[0]).toEqual('

Nowhere

'); + }) + + 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'); + }) }); \ No newline at end of file