1
1
var TypeScript = require ( './typescript-services' ) ;
2
2
var TypeKind = require ( './TypeKind' ) ;
3
- var prism = require ( './prism' ) ;
4
3
var { Seq } = require ( 'immutable' ) ;
5
- var marked = require ( 'marked' ) ;
6
4
7
5
8
6
class DocVisitor extends TypeScript . SyntaxWalker {
@@ -90,14 +88,14 @@ class DocVisitor extends TypeScript.SyntaxWalker {
90
88
if ( ! shouldIgnore ( comment ) && ! this . isAliased ( name ) ) {
91
89
this . addAliases ( comment , name ) ;
92
90
93
- var callSignature = this . parseCallSignature ( node . callSignature ) ;
94
- callSignature . line = this . getLineNum ( node ) ;
95
- pushIn ( this . data , [ name , 'call' , 'signatures' ] , callSignature ) ;
96
-
97
91
var comment = this . getDoc ( node ) ;
98
92
if ( comment ) {
99
93
setIn ( this . data , [ name , 'call' , 'doc' ] , comment ) ;
100
94
}
95
+
96
+ var callSignature = this . parseCallSignature ( node . callSignature ) ;
97
+ callSignature . line = this . getLineNum ( node ) ;
98
+ pushIn ( this . data , [ name , 'call' , 'signatures' ] , callSignature ) ;
101
99
}
102
100
super . visitFunctionDeclaration ( node ) ;
103
101
}
@@ -191,13 +189,13 @@ class DocVisitor extends TypeScript.SyntaxWalker {
191
189
// name: name // redundant
192
190
} ;
193
191
194
- setIn ( last ( this . data . groups ) , [ 'properties' , '#' + name ] , propertyObj ) ;
195
-
196
192
var comment = this . getDoc ( node ) ;
197
193
if ( comment ) {
198
- setIn ( last ( this . data . groups ) , [ 'properties ' , '#' + name , 'doc' ] , comment ) ;
194
+ setIn ( last ( this . data . groups ) , [ 'members ' , '#' + name , 'doc' ] , comment ) ;
199
195
}
200
196
197
+ setIn ( last ( this . data . groups ) , [ 'members' , '#' + name ] , propertyObj ) ;
198
+
201
199
if ( node . questionToken ) {
202
200
throw new Error ( 'NYI: questionToken' ) ;
203
201
}
@@ -217,15 +215,15 @@ class DocVisitor extends TypeScript.SyntaxWalker {
217
215
218
216
this . ensureGroup ( node ) ;
219
217
220
- var callSignature = this . parseCallSignature ( node . callSignature ) ;
221
- callSignature . line = this . getLineNum ( node ) ;
222
- pushIn ( last ( this . data . groups ) , [ 'methods' , '#' + name , 'signatures' ] , callSignature ) ;
223
-
224
218
var comment = this . getDoc ( node ) ;
225
219
if ( comment ) {
226
- setIn ( last ( this . data . groups ) , [ 'methods ' , '#' + name , 'doc' ] , comment ) ;
220
+ setIn ( last ( this . data . groups ) , [ 'members ' , '#' + name , 'doc' ] , comment ) ;
227
221
}
228
222
223
+ var callSignature = this . parseCallSignature ( node . callSignature ) ;
224
+ callSignature . line = this . getLineNum ( node ) ;
225
+ pushIn ( last ( this . data . groups ) , [ 'members' , '#' + name , 'signatures' ] , callSignature ) ;
226
+
229
227
if ( node . questionToken ) {
230
228
throw new Error ( 'NYI: questionToken' ) ;
231
229
}
@@ -404,69 +402,23 @@ function parseComment(node) {
404
402
var notes = lines
405
403
. map ( l => l . match ( COMMENT_NOTE_RX ) )
406
404
. filter ( n => n !== null && ! NOTE_BLACKLIST [ n [ 1 ] ] )
407
- . map ( n => {
408
- var name = n [ 1 ] ;
409
- var body = n [ 2 ] ;
410
- if ( name !== 'alias' ) {
411
- body = parseMarkdown ( body ) ;
412
- }
413
- return { name, body } ;
414
- } ) ;
405
+ . map ( n => ( { name : n [ 1 ] , body : n [ 2 ] } ) ) ;
415
406
var paragraphs =
416
407
lines . filter ( l => ! COMMENT_NOTE_RX . test ( l ) ) . join ( '\n' ) . split ( '\n\n' ) ;
417
- var synopsis = parseMarkdown ( paragraphs . shift ( ) ) ;
408
+ var synopsis = paragraphs . shift ( ) ;
418
409
var description = paragraphs . join ( '\n\n' ) ;
419
410
420
411
var comment = { synopsis } ;
421
412
if ( notes . length ) {
422
413
comment . notes = notes ;
423
414
}
424
415
if ( description ) {
425
- comment . description = parseMarkdown ( description ) ;
416
+ comment . description = description ;
426
417
}
427
418
428
419
return comment ;
429
420
}
430
421
431
- // functions come before keywords
432
- prism . languages . insertBefore ( 'javascript' , 'keyword' , {
433
- 'block-keyword' : / \b ( i f | e l s e | w h i l e | f o r | f u n c t i o n ) \b / g,
434
- 'function' : prism . languages . function
435
- } ) ;
436
-
437
- marked . setOptions ( {
438
- highlight : function ( code ) {
439
- return prism . highlight ( code , prism . languages . javascript ) ;
440
- }
441
- } ) ;
442
-
443
- var renderer = new marked . Renderer ( ) ;
444
-
445
- renderer . code = function ( code , lang , escaped ) {
446
- if ( this . options . highlight ) {
447
- var out = this . options . highlight ( code , lang ) ;
448
- if ( out != null && out !== code ) {
449
- escaped = true ;
450
- code = out ;
451
- }
452
- }
453
- return '<code class="codeBlock">' +
454
- ( escaped ? code : escapeCode ( code , true ) ) +
455
- '</code>' ;
456
- } ;
457
-
458
- function escapeCode ( code ) {
459
- return code
460
- . replace ( / & / g, '&' )
461
- . replace ( / < / g, '<' )
462
- . replace ( / > / g, '>' )
463
- . replace ( / " / g, '"' )
464
- . replace ( / ' / g, ''' ) ;
465
- }
466
-
467
- function parseMarkdown ( content ) {
468
- return content ? marked ( content , { renderer } ) : content ;
469
- }
470
422
471
423
function shouldIgnore ( comment ) {
472
424
return ! ! ( comment && Seq ( comment . notes ) . find (
0 commit comments