From 7b725ae718b63a7aa4f24db0d5d6ae3de90b6d69 Mon Sep 17 00:00:00 2001 From: Ryuichi Okumura Date: Wed, 18 Feb 2015 20:55:49 +0900 Subject: [PATCH] Fix a bug with "@" doesn't escapable in example The issue due to non JSDoc tags such as `@media` recognized as JSDoc tags. It avoid the problem by ignoring tags of the target. Fix #179. --- lib/docparser.js | 16 +++++++++++++++- tests/input/test/test.js | 7 +++++++ tests/parser.js | 4 ++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/docparser.js b/lib/docparser.js index 718c7697..266cb191 100644 --- a/lib/docparser.js +++ b/lib/docparser.js @@ -171,6 +171,18 @@ YUI.add('docparser', function (Y) { "writeonce" // YUI attribute config ], + /** + * A list of ignored tags. These tags should be ignored because there is + * likely to be used for purposes other than JSDoc tags in JavaScript comments. + * @property IGNORE_TAGLIST + * @type Array + * @final + * @for DocParser + */ + IGNORE_TAGLIST = [ + "media" + ], + /** * Common errors will get scrubbed instead of being ignored. * @property CORRECTIONS @@ -1128,6 +1140,7 @@ YUI.add('docparser', function (Y) { var lines = comment.split(REGEX_LINES), len = lines.length, i, + regex, parts, part, peek, skip, tag, value, results = [{ @@ -1150,7 +1163,8 @@ YUI.add('docparser', function (Y) { // reconsitute and tokenize the comment block comment = this.unindent(lines.join('\n')); - parts = comment.split(/(?:^|\n)\s*(@\w*)/); + regex = new RegExp('(?:^|\\n)\\s*((?!@' + IGNORE_TAGLIST.join(')(?!@') + ')@\\w*)'); + parts = comment.split(regex); len = parts.length; for (i = 0; i < len; i++) { value = ''; diff --git a/tests/input/test/test.js b/tests/input/test/test.js index 0742cabf..7a7609cb 100644 --- a/tests/input/test/test.js +++ b/tests/input/test/test.js @@ -158,6 +158,13 @@ This is the description **/ +/** +@method foo2 +@example + @media screen and (max-width: 767px) { + } +*/ + /** Other Class @class OtherClass diff --git a/tests/parser.js b/tests/parser.js index 6fe7aa1e..d18e7b5b 100644 --- a/tests/parser.js +++ b/tests/parser.js @@ -440,6 +440,10 @@ suite.add(new YUITest.TestCase({ Assert.areSame(item.params[0].props[0].name, 'name'); Assert.isTrue(item.params[0].props[0].optional); + }, + 'test: markdown example': function () { + var item = this.findByName('foo2', 'myclass'); + Assert.areSame(item.example[0], '\n @media screen and (max-width: 767px) {\n }'); } }));