@@ -22,9 +22,8 @@ const checkPossibleType = node =>
22
22
/**
23
23
* Gets a list of properties from a typed list
24
24
* @param {import('mdast').List } node
25
- * @param {string } prefix
26
25
*/
27
- export const parseListIntoProperties = ( node , prefix = '' ) => {
26
+ export const parseListIntoProperties = node => {
28
27
const properties = [ ] ;
29
28
30
29
for ( const item of node . children ) {
@@ -34,9 +33,7 @@ export const parseListIntoProperties = (node, prefix = '') => {
34
33
const [ { children } , ...otherChildren ] = item . children ;
35
34
36
35
if ( children [ 0 ] . type === 'inlineCode' ) {
37
- name = (
38
- prefix ? `${ prefix } .${ children . shift ( ) . value } ` : children . shift ( ) . value
39
- ) . trimEnd ( ) ;
36
+ name = children . shift ( ) . value . trimEnd ( ) ;
40
37
} else if ( children [ 0 ] . value && children [ 0 ] . value . startsWith ( 'Returns' ) ) {
41
38
children . shift ( ) ;
42
39
name = 'Returns' ;
@@ -65,14 +62,12 @@ export const parseListIntoProperties = (node, prefix = '') => {
65
62
children [ 0 ] . value = children [ 0 ] . value . trimStart ( ) ;
66
63
}
67
64
68
- properties . push ( { name, types, desc : children } ) ;
69
-
70
- const sublist = otherChildren . find ( createQueries . UNIST . isTypedList ) ;
71
- if ( sublist ) {
72
- properties . push (
73
- ...parseListIntoProperties ( sublist , name === 'Returns' ? '_' : name )
74
- ) ;
75
- }
65
+ properties . push ( {
66
+ name,
67
+ types,
68
+ desc : children ,
69
+ sublist : otherChildren . find ( createQueries . UNIST . isTypedList ) ,
70
+ } ) ;
76
71
}
77
72
78
73
return properties ;
@@ -81,33 +76,19 @@ export const parseListIntoProperties = (node, prefix = '') => {
81
76
/**
82
77
* Creates a property table
83
78
* @param {import('mdast').List } node
79
+ * @param {boolean } withHeading
84
80
* @returns {import('hast').Element }
85
81
*/
86
- export const createPropertyTable = node => {
82
+ export const createPropertyTable = ( node , withHeading = true ) => {
87
83
const properties = parseListIntoProperties ( node ) ;
88
84
89
85
// Determine which columns to show based on data availability
90
86
const hasName = properties . some ( prop => prop . name ) ;
91
87
const hasType = properties . some ( prop => prop . types . length > 0 ) ;
92
88
const hasDesc = properties . some ( prop => prop . desc . length > 0 ) ;
93
89
94
- // Create table headers based on available data
95
- const headers = [ ] ;
96
-
97
- if ( hasName ) {
98
- headers . push ( createElement ( 'th' , 'Property' ) ) ;
99
- }
100
-
101
- if ( hasType ) {
102
- headers . push ( createElement ( 'th' , 'Type' ) ) ;
103
- }
104
-
105
- if ( hasDesc ) {
106
- headers . push ( createElement ( 'th' , 'Description' ) ) ;
107
- }
108
-
109
90
// Create table rows
110
- const rows = properties . map ( prop => {
91
+ const rows = properties . flatMap ( prop => {
111
92
const cells = [ ] ;
112
93
113
94
if ( hasName ) {
@@ -128,16 +109,44 @@ export const createPropertyTable = node => {
128
109
cells . push ( createElement ( 'td' , prop . desc ) ) ;
129
110
}
130
111
131
- return createElement ( 'tr' , cells ) ;
112
+ return prop . sublist
113
+ ? [
114
+ createElement ( 'tr' , cells ) ,
115
+ createElement (
116
+ 'tr' ,
117
+ createElement (
118
+ 'td' ,
119
+ { colspan : cells . length } ,
120
+ createPropertyTable ( prop . sublist , false )
121
+ )
122
+ ) ,
123
+ ]
124
+ : createElement ( 'tr' , cells ) ;
132
125
} ) ;
133
126
134
- // Create the table element
135
- const table = createElement ( 'table' , [
136
- createElement ( 'thead' , [ createElement ( 'tr' , headers ) ] ) ,
137
- createElement ( 'tbody' , rows ) ,
138
- ] ) ;
127
+ if ( withHeading ) {
128
+ // Create table headers based on available data
129
+ const headers = [ ] ;
130
+
131
+ if ( hasName ) {
132
+ headers . push ( createElement ( 'th' , 'Property' ) ) ;
133
+ }
134
+
135
+ if ( hasType ) {
136
+ headers . push ( createElement ( 'th' , 'Type' ) ) ;
137
+ }
138
+
139
+ if ( hasDesc ) {
140
+ headers . push ( createElement ( 'th' , 'Description' ) ) ;
141
+ }
142
+
143
+ return createElement ( 'table' , [
144
+ createElement ( 'thead' , [ createElement ( 'tr' , headers ) ] ) ,
145
+ createElement ( 'tbody' , rows ) ,
146
+ ] ) ;
147
+ }
139
148
140
- return table ;
149
+ return createElement ( ' table' , createElement ( 'tbody' , rows ) ) ;
141
150
} ;
142
151
143
152
/**
0 commit comments