Skip to content

Commit

Permalink
Fix a bug with "@" doesn't escapable in example
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
okuryu committed Feb 18, 2015
1 parent 5d3644d commit 7b725ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/docparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = [{
Expand All @@ -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 = '';
Expand Down
7 changes: 7 additions & 0 deletions tests/input/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,13 @@ This is the description
**/

/**
@method foo2
@example
@media screen and (max-width: 767px) {
}
*/

/**
Other Class
@class OtherClass
Expand Down
4 changes: 4 additions & 0 deletions tests/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }');
}
}));

Expand Down

0 comments on commit 7b725ae

Please sign in to comment.