1+ import { highlightToHast } from '@node-core/rehype-shiki' ;
12import { h as createElement } from 'hastscript' ;
23
34import createQueries from '../../../utils/queries/index.mjs' ;
@@ -200,7 +201,7 @@ export const generateSignatures = (functionName, signature) => {
200201export const createSignatureCodeBlock = ( functionName , signature ) => {
201202 const signatures = generateSignatures ( functionName , signature ) ;
202203 const codeContent = signatures . join ( '\n' ) ;
203- return createElement ( 'pre' , codeContent ) ;
204+ return highlightToHast ( codeContent , 'typescript' ) ;
204205} ;
205206
206207/**
@@ -226,36 +227,16 @@ export const getFullName = ({ name, text }, fallback = name) => {
226227 * Creates documentation from API metadata entries
227228 * @param {import('@types/mdast').Parent } parent - The parent node
228229 * @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
231231 */
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 ) ;
237235
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 ) : [ ] ;
241237
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 ) ;
244240
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 ) ) ;
261242} ;
0 commit comments