88import { readFileSync , readdirSync } from 'node:fs' ;
99import { join } from 'node:path' ;
1010import Handlebars from 'handlebars' ;
11- import { getAnchor , cleanId } from './helpers.js' ;
11+ import { getAnchor , cleanId , stripMarkdownLinks } from './helpers.js' ;
1212import type { AnchorMap } from './helpers.js' ;
1313import { log } from './logger.js' ;
1414import type { Compound , MoxygenOptions } from './types.js' ;
@@ -37,6 +37,25 @@ export function registerHelpers(options: Pick<MoxygenOptions, 'anchors' | 'htmlA
3737
3838 Handlebars . registerHelper ( 'or' , ( a : unknown , b : unknown ) => a || b ) ;
3939
40+ Handlebars . registerHelper ( 'compoundsOfKind' , ( compounds : unknown , ...args : unknown [ ] ) => {
41+ const options = args [ args . length - 1 ] ;
42+ void options ;
43+ const kinds = new Set (
44+ args
45+ . slice ( 0 , - 1 )
46+ . filter ( ( value ) : value is string => typeof value === 'string' ) ,
47+ ) ;
48+ if ( ! Array . isArray ( compounds ) || ! kinds . size ) {
49+ return [ ] ;
50+ }
51+ return compounds . filter ( ( compound ) =>
52+ compound &&
53+ typeof compound === 'object' &&
54+ 'kind' in compound &&
55+ kinds . has ( ( compound as Record < string , unknown > ) . kind as string ) ,
56+ ) ;
57+ } ) ;
58+
4059 Handlebars . registerHelper ( 'shortname' , ( fullname : string ) => {
4160 const parts = ( fullname || '' ) . split ( '::' ) ;
4261 return parts [ parts . length - 1 ] || fullname ;
@@ -52,27 +71,35 @@ export function registerHelpers(options: Pick<MoxygenOptions, 'anchors' | 'htmlA
5271 if ( kind === 'variable' ) {
5372 const init = member . initializer as string ;
5473 return init
55- ? `${ member . returnType } ${ member . name } ${ init } `
56- : `${ member . returnType } ${ member . name } ` ;
74+ ? `${ stripMarkdownLinks ( member . returnType as string ) } ${ member . name } ${ init } `
75+ : `${ stripMarkdownLinks ( member . returnType as string ) } ${ member . name } ` ;
5776 }
5877 if ( kind === 'property' ) {
59- return `${ member . returnType } ${ member . name } ` ;
78+ return `${ stripMarkdownLinks ( member . returnType as string ) } ${ member . name } ` ;
6079 }
6180
6281 // function/signal/slot
6382 const parts : string [ ] = [ ] ;
6483 const tparams = member . templateParams as Array < { type : string ; name : string } > ;
6584 if ( tparams && tparams . length > 0 ) {
66- parts . push ( 'template<' + tparams . map ( tp => tp . name ? `${ tp . type } ${ tp . name } ` : tp . type ) . join ( ', ' ) + '>' ) ;
85+ parts . push ( 'template<' + tparams . map ( tp => {
86+ const type = stripMarkdownLinks ( tp . type ) ;
87+ return tp . name ? `${ type } ${ tp . name } ` : type ;
88+ } ) . join ( ', ' ) + '>' ) ;
6789 }
6890 if ( member . isVirtual ) parts . push ( 'virtual' ) ;
6991 if ( member . isStatic ) parts . push ( 'static' ) ;
7092 if ( member . isInline ) parts . push ( 'inline' ) ;
7193 if ( member . isExplicit ) parts . push ( 'explicit' ) ;
7294 const rt = member . returnType as string ;
73- if ( rt ) parts . push ( rt ) ;
95+ if ( rt ) parts . push ( stripMarkdownLinks ( rt ) ) ;
7496 const params = member . params as Array < { type : string ; name : string } > ;
75- const paramStr = params ? params . map ( p => p . name ? `${ p . type } ${ p . name } ` : p . type ) . join ( ', ' ) : '' ;
97+ const paramStr = params
98+ ? params . map ( ( p ) => {
99+ const type = stripMarkdownLinks ( p . type ) ;
100+ return p . name ? `${ type } ${ p . name } ` : type ;
101+ } ) . join ( ', ' )
102+ : '' ;
76103 parts . push ( `${ member . name } (${ paramStr } )` ) ;
77104 const qualifiers = member . qualifiers as string [ ] ;
78105 if ( qualifiers ) {
0 commit comments