1
1
'use strict' ;
2
2
3
3
var doctrine = require ( 'doctrine' ) ;
4
+ var remark = require ( 'remark' ) ;
5
+ var inlineTokenizer = require ( './inline_tokenizer' ) ;
6
+
7
+ function parseMarkdown ( string ) {
8
+ return remark . use ( inlineTokenizer ) . parse ( string ) ;
9
+ }
4
10
5
11
var flatteners = {
6
12
'abstract' : flattenBoolean ,
@@ -10,22 +16,27 @@ var flatteners = {
10
16
'alias' : flattenName ,
11
17
'arg' : synonym ( 'param' ) ,
12
18
'argument' : synonym ( 'param' ) ,
13
- 'augments' : collect ( 'augments' ) ,
19
+ 'augments' : function ( result , tag ) {
20
+ if ( ! result . augments ) {
21
+ result . augments = [ ] ;
22
+ }
23
+ result . augments . push ( tag ) ;
24
+ } ,
14
25
'author' : flattenDescription ,
15
26
'borrows' : todo ,
16
27
'callback' : flattenDescription ,
17
28
'class' : flattenTypedName ,
18
- 'classdesc' : flattenDescription ,
29
+ 'classdesc' : flattenMarkdownDescription ,
19
30
'const' : synonym ( 'constant' ) ,
20
31
'constant' : flattenTypedName ,
21
32
'constructor' : synonym ( 'class' ) ,
22
33
'constructs' : todo ,
23
- 'copyright' : flattenDescription ,
34
+ 'copyright' : flattenMarkdownDescription ,
24
35
'default' : todo ,
25
36
'defaultvalue' : synonym ( 'default' ) ,
26
- 'deprecated' : flattenDescription ,
37
+ 'deprecated' : flattenMarkdownDescription ,
27
38
'desc' : synonym ( 'description' ) ,
28
- 'description' : flattenDescription ,
39
+ 'description' : flattenMarkdownDescription ,
29
40
'emits' : synonym ( 'fires' ) ,
30
41
'enum' : todo ,
31
42
'event' : flattenDescription ,
@@ -47,7 +58,7 @@ var flatteners = {
47
58
} ;
48
59
49
60
if ( tag . caption ) {
50
- example . caption = tag . caption ;
61
+ example . caption = parseMarkdown ( tag . caption ) ;
51
62
}
52
63
53
64
result . examples . push ( example ) ;
@@ -98,12 +109,50 @@ var flatteners = {
98
109
'namespace' : flattenTypedName ,
99
110
'override' : flattenBoolean ,
100
111
'overview' : synonym ( 'file' ) ,
101
- 'param' : collect ( 'params' ) ,
112
+ 'param' : function ( result , tag ) {
113
+ if ( ! result . params ) {
114
+ result . params = [ ] ;
115
+ }
116
+
117
+ var param = {
118
+ name : tag . name ,
119
+ lineNumber : tag . lineNumber // TODO: remove
120
+ } ;
121
+
122
+ if ( tag . description ) {
123
+ param . description = parseMarkdown ( tag . description ) ;
124
+ }
125
+
126
+ if ( tag . type ) {
127
+ param . type = tag . type ;
128
+ }
129
+
130
+ result . params . push ( param ) ;
131
+ } ,
102
132
'private' : function ( result ) {
103
133
result . access = 'private' ;
104
134
} ,
105
135
'prop' : synonym ( 'property' ) ,
106
- 'property' : collect ( 'properties' ) ,
136
+ 'property' : function ( result , tag ) {
137
+ if ( ! result . properties ) {
138
+ result . properties = [ ] ;
139
+ }
140
+
141
+ var property = {
142
+ name : tag . name ,
143
+ lineNumber : tag . lineNumber // TODO: remove
144
+ } ;
145
+
146
+ if ( tag . description ) {
147
+ property . description = parseMarkdown ( tag . description ) ;
148
+ }
149
+
150
+ if ( tag . type ) {
151
+ property . type = tag . type ;
152
+ }
153
+
154
+ result . properties . push ( property ) ;
155
+ } ,
107
156
'protected' : function ( result ) {
108
157
result . access = 'protected' ;
109
158
} ,
@@ -113,16 +162,56 @@ var flatteners = {
113
162
'readonly' : flattenBoolean ,
114
163
'requires' : todo ,
115
164
'return' : synonym ( 'returns' ) ,
116
- 'returns' : collect ( 'returns' ) ,
117
- 'see' : collect ( 'sees' , true ) ,
165
+ 'returns' : function ( result , tag ) {
166
+ if ( ! result . returns ) {
167
+ result . returns = [ ] ;
168
+ }
169
+
170
+ var returns = {
171
+ description : parseMarkdown ( tag . description )
172
+ } ;
173
+
174
+ if ( tag . type ) {
175
+ returns . type = tag . type ;
176
+ }
177
+
178
+ result . returns . push ( returns ) ;
179
+ } ,
180
+ 'see' : function ( result , tag ) {
181
+ if ( ! result . sees ) {
182
+ result . sees = [ ] ;
183
+ }
184
+ result . sees . push ( parseMarkdown ( tag . description ) ) ;
185
+ } ,
118
186
'since' : flattenDescription ,
119
187
'static' : function ( result ) {
120
188
result . scope = 'static' ;
121
189
} ,
122
- 'summary' : flattenDescription ,
190
+ 'summary' : flattenMarkdownDescription ,
123
191
'this' : todo ,
124
- 'throws' : collect ( 'throws' ) ,
125
- 'todo' : collect ( 'todos' , true ) ,
192
+ 'throws' : function ( result , tag ) {
193
+ if ( ! result . throws ) {
194
+ result . throws = [ ] ;
195
+ }
196
+
197
+ var throws = { } ;
198
+
199
+ if ( tag . description ) {
200
+ throws . description = parseMarkdown ( tag . description ) ;
201
+ }
202
+
203
+ if ( tag . type ) {
204
+ throws . type = tag . type ;
205
+ }
206
+
207
+ result . throws . push ( throws ) ;
208
+ } ,
209
+ 'todo' : function ( result , tag ) {
210
+ if ( ! result . todos ) {
211
+ result . todos = [ ] ;
212
+ }
213
+ result . todos . push ( parseMarkdown ( tag . description ) ) ;
214
+ } ,
126
215
'tutorial' : todo ,
127
216
'type' : todo ,
128
217
'typedef' : flattenTypedName ,
@@ -136,19 +225,6 @@ var flatteners = {
136
225
137
226
function todo ( ) { }
138
227
139
- function collect ( key , description ) {
140
- return function ( result , tag ) {
141
- if ( ! result [ key ] ) {
142
- result [ key ] = [ ] ;
143
- }
144
- if ( description ) {
145
- result [ key ] . push ( tag . description ) ;
146
- } else {
147
- result [ key ] . push ( tag ) ;
148
- }
149
- } ;
150
- }
151
-
152
228
function synonym ( key ) {
153
229
return function ( result , tag ) {
154
230
return flatteners [ key ] ( result , tag , key ) ;
@@ -167,6 +243,10 @@ function flattenDescription(result, tag, key) {
167
243
result [ key ] = tag . description ;
168
244
}
169
245
246
+ function flattenMarkdownDescription ( result , tag , key ) {
247
+ result [ key ] = parseMarkdown ( tag . description ) ;
248
+ }
249
+
170
250
function flattenTypedName ( result , tag , key ) {
171
251
result [ key ] = {
172
252
name : tag . name
@@ -269,6 +349,10 @@ function parseJSDoc(comment, loc, context) {
269
349
result . context = context ;
270
350
result . errors = [ ] ;
271
351
352
+ if ( result . description ) {
353
+ result . description = parseMarkdown ( result . description ) ;
354
+ }
355
+
272
356
result . tags . forEach ( function ( tag ) {
273
357
if ( tag . errors ) {
274
358
for ( var j = 0 ; j < tag . errors . length ; j ++ ) {
0 commit comments