1
+ import { highlightToHast } from '@node-core/rehype-shiki' ;
1
2
import { h as createElement } from 'hastscript' ;
2
3
3
4
import createQueries from '../../../utils/queries/index.mjs' ;
@@ -200,7 +201,7 @@ export const generateSignatures = (functionName, signature) => {
200
201
export const createSignatureCodeBlock = ( functionName , signature ) => {
201
202
const signatures = generateSignatures ( functionName , signature ) ;
202
203
const codeContent = signatures . join ( '\n' ) ;
203
- return createElement ( 'pre' , codeContent ) ;
204
+ return highlightToHast ( codeContent , 'typescript' ) ;
204
205
} ;
205
206
206
207
/**
@@ -226,36 +227,16 @@ export const getFullName = ({ name, text }, fallback = name) => {
226
227
* Creates documentation from API metadata entries
227
228
* @param {import('@types/mdast').Parent } parent - The parent node
228
229
* @param {import('@types/mdast').Heading } heading - The heading
229
- * @param {number } backupIndex - If there isn't a list, use this index
230
- * @param {boolean } addSignatureCodebox - Is this a method?
230
+ * @param {number } idx - Index
231
231
*/
232
- export default ( parent , heading , backupIndex , addSignatureCodebox ) => {
233
- // Find the list index in the parent
234
- const listIdx = parent . children . findIndex ( createQueries . UNIST . isTypedList ) ;
235
- const list = parent . children [ listIdx ] ;
236
- const elements = [ ] ;
232
+ export default ( { children } , { data } , idx ) => {
233
+ // Find the list in the parent
234
+ const list = children . find ( createQueries . UNIST . isTypedList ) ;
237
235
238
- // Create a signature code box, if this is a method/ctor.
239
- if ( addSignatureCodebox ) {
240
- const params = list ? list . children . map ( parseListItem ) : [ ] ;
236
+ const params = list ? list . children . map ( parseListItem ) : [ ] ;
241
237
242
- const signature = parseSignature ( heading . data . text , params ) ;
243
- const displayName = getFullName ( heading . data ) ;
238
+ const signature = parseSignature ( data . text , params ) ;
239
+ const displayName = getFullName ( data ) ;
244
240
245
- elements . push ( createSignatureCodeBlock ( displayName , signature ) ) ;
246
- }
247
-
248
- // Create property table if a list exists
249
- if ( list ) {
250
- elements . push ( createPropertyTable ( list ) ) ;
251
- }
252
-
253
- // Replace the list in the parent with all collected elements
254
- if ( elements . length > 0 ) {
255
- if ( listIdx > - 1 ) {
256
- parent . children . splice ( listIdx , 1 , ...elements ) ;
257
- } else {
258
- parent . children . splice ( backupIndex , 0 , ...elements ) ;
259
- }
260
- }
241
+ children . splice ( idx , 0 , createSignatureCodeBlock ( displayName , signature ) ) ;
261
242
} ;
0 commit comments