@@ -22,9 +22,8 @@ const checkPossibleType = node =>
2222/**
2323 * Gets a list of properties from a typed list
2424 * @param {import('mdast').List } node
25- * @param {string } prefix
2625 */
27- export const parseListIntoProperties = ( node , prefix = '' ) => {
26+ export const parseListIntoProperties = node => {
2827 const properties = [ ] ;
2928
3029 for ( const item of node . children ) {
@@ -34,9 +33,7 @@ export const parseListIntoProperties = (node, prefix = '') => {
3433 const [ { children } , ...otherChildren ] = item . children ;
3534
3635 if ( children [ 0 ] . type === 'inlineCode' ) {
37- name = (
38- prefix ? `${ prefix } .${ children . shift ( ) . value } ` : children . shift ( ) . value
39- ) . trimEnd ( ) ;
36+ name = children . shift ( ) . value . trimEnd ( ) ;
4037 } else if ( children [ 0 ] . value && children [ 0 ] . value . startsWith ( 'Returns' ) ) {
4138 children . shift ( ) ;
4239 name = 'Returns' ;
@@ -65,14 +62,12 @@ export const parseListIntoProperties = (node, prefix = '') => {
6562 children [ 0 ] . value = children [ 0 ] . value . trimStart ( ) ;
6663 }
6764
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+ } ) ;
7671 }
7772
7873 return properties ;
@@ -81,33 +76,19 @@ export const parseListIntoProperties = (node, prefix = '') => {
8176/**
8277 * Creates a property table
8378 * @param {import('mdast').List } node
79+ * @param {boolean } withHeading
8480 * @returns {import('hast').Element }
8581 */
86- export const createPropertyTable = node => {
82+ export const createPropertyTable = ( node , withHeading = true ) => {
8783 const properties = parseListIntoProperties ( node ) ;
8884
8985 // Determine which columns to show based on data availability
9086 const hasName = properties . some ( prop => prop . name ) ;
9187 const hasType = properties . some ( prop => prop . types . length > 0 ) ;
9288 const hasDesc = properties . some ( prop => prop . desc . length > 0 ) ;
9389
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-
10990 // Create table rows
110- const rows = properties . map ( prop => {
91+ const rows = properties . flatMap ( prop => {
11192 const cells = [ ] ;
11293
11394 if ( hasName ) {
@@ -128,16 +109,44 @@ export const createPropertyTable = node => {
128109 cells . push ( createElement ( 'td' , prop . desc ) ) ;
129110 }
130111
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 ) ;
132125 } ) ;
133126
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+ }
139148
140- return table ;
149+ return createElement ( ' table' , createElement ( 'tbody' , rows ) ) ;
141150} ;
142151
143152/**
0 commit comments