@@ -19,13 +19,19 @@ export default defineGenerator({
19
19
} ) ;
20
20
21
21
function renderSchema ( schema : Schema , opts : { headingLevel : number } ) {
22
- const md : string [ ] = [ ] ;
22
+ const sections = Object . create ( null ) as Record < string , [ string , string [ ] ] [ ] > ;
23
+
23
24
for ( const [ name , meta ] of Object . entries ( schema . properties || { } ) ) {
24
25
// Only functions
25
- if ( meta . type !== "function" ) {
26
+ if (
27
+ meta . type !== "function" ||
28
+ meta . default ?. toString ?.( ) . startsWith ( "class" )
29
+ ) {
26
30
continue ;
27
31
}
28
32
33
+ const lines : string [ ] = [ ] ;
34
+
29
35
// Parse tag annotations
30
36
const tags = parseTags ( meta . tags ) ;
31
37
@@ -36,28 +42,44 @@ function renderSchema(schema: Schema, opts: { headingLevel: number }) {
36
42
37
43
const jsSig = `${ name } (${ ( meta . args || [ ] ) . map ( ( arg ) => arg . name ) . join ( ", " ) } )` ;
38
44
39
- md . push ( `${ "#" . repeat ( opts . headingLevel ) } \`${ jsSig } \`` , "" ) ;
45
+ lines . push ( `${ "#" . repeat ( opts . headingLevel + 1 ) } \`${ jsSig } \`` , "" ) ;
40
46
41
47
if ( meta . title ) {
42
- md . push ( meta . title . trim ( ) ) ;
48
+ lines . push ( meta . title . trim ( ) ) ;
43
49
}
44
50
if ( meta . description ) {
45
- md . push ( "" , meta . description . trim ( ) ) ;
51
+ lines . push ( "" , meta . description . trim ( ) ) ;
46
52
}
47
53
48
54
for ( const tag of tags ) {
49
55
if ( tag . tag === "@example" ) {
50
56
const codeBlock = tag . contents . startsWith ( "`" )
51
57
? tag . contents
52
58
: `\`\`\`ts\n${ tag . contents } \n\`\`\`` ;
53
- md . push ( "" , "**Example:**" , "" , codeBlock ) ;
59
+ lines . push ( "" , "**Example:**" , "" , codeBlock ) ;
54
60
}
55
61
}
56
62
57
- md . push ( "" ) ;
63
+ lines . push ( "" ) ;
64
+
65
+ const group = tags . find ( ( t ) => t . tag === "@group" ) ?. contents || "" ;
66
+ sections [ group ] = sections [ group ] || [ ] ;
67
+ sections [ group ] . push ( [ name , lines ] ) ;
68
+ }
69
+
70
+ const lines : string [ ] = [ ] ;
71
+ for ( const group of Object . keys ( sections ) . sort ( ) ) {
72
+ if ( group ) {
73
+ lines . push ( `${ "#" . repeat ( opts . headingLevel ) } ${ group } ` , "" ) ;
74
+ }
75
+ for ( const item of sections [ group ] . sort ( ( i1 , i2 ) =>
76
+ i1 [ 0 ] . localeCompare ( i2 [ 0 ] ) ,
77
+ ) ) {
78
+ lines . push ( ...item [ 1 ] ) ;
79
+ }
58
80
}
59
81
60
- return md . join ( "\n" ) ;
82
+ return lines . join ( "\n" ) ;
61
83
}
62
84
63
85
function parseTags ( lines : string [ ] = [ ] ) {
0 commit comments