@@ -126,15 +126,51 @@ const renderHTML = (mat: any) => {
126126 temp = `<tr>${ temp } </tr>` ;
127127 } else {
128128 const { count : innerCount , body : innerBody } = renderHTML ( val ) ;
129- count += innerCount ;
130- temp += `<th rowspan="${ count } ">${ key } </th>` ;
129+ temp += `<th rowspan="${ innerCount } ">${ key } </th>` ;
131130 temp += innerBody ;
132131 }
133132 body += temp ;
134133 }
135134 return { count, body } ;
136135} ;
137136
137+ // chatGPT
138+ function createRecursiveTable ( data : NestedData ) : string {
139+ let html = "<table border='1'>" ;
140+ html += "<thead><tr><th>Key</th><th>Value</th></tr></thead><tbody>" ;
141+
142+ function traverse ( obj : NestedData | number [ ] , depth = 0 ) : string {
143+ let rows = "" ;
144+
145+ if ( Array . isArray ( obj ) ) {
146+ // 配列の場合、単純に値を出力
147+ rows += `<td>${ obj . join ( ", " ) } </td></tr>` ;
148+ } else {
149+ for ( const key in obj ) {
150+ const value = obj [ key ] ;
151+ const rowspan = countRows ( value ) ;
152+
153+ rows += `<tr>` ;
154+ rows += `<td rowspan="${ rowspan } ">${ key } </td>` ;
155+
156+ if ( Array . isArray ( value ) ) {
157+ // 次が配列なら、すぐ値を出す
158+ rows += `<td>${ value . join ( ", " ) } </td></tr>` ;
159+ } else {
160+ // 次がオブジェクトなら、さらに潜る
161+ rows += traverse ( value , depth + 1 ) ;
162+ }
163+ }
164+ }
165+
166+ return rows ;
167+ }
168+
169+ html += traverse ( data ) ;
170+ html += "</tbody></table>" ;
171+ return html ;
172+ }
173+
138174console . log ( "body is" , body ) ;
139175
140176if ( body ) {
@@ -150,6 +186,7 @@ if (body) {
150186 <tbody>${ renderHTML ( matrix ) . body } </tbody>
151187 </table>
152188 ` ;
189+ body += createRecursiveTable ( matrix ) ;
153190 octokit . rest . issues . createComment ( {
154191 owner,
155192 repo,
0 commit comments