@@ -65,15 +65,39 @@ export default (ctx) => ({
6565 return null ;
6666 } ,
6767
68- renderExamples ( comment ) {
69- if ( ! comment || ! comment . blockTags ) return "" ;
70- const examples = comment . blockTags . filter ( ( tag ) => tag . tag === "@example" ) ;
68+ /**
69+ * Renders `@example` tags from a comment as Markdown.
70+ * Pass `headingLevel` to prepend a heading (block context);
71+ * omit it for inline use (e.g. inside a list item).
72+ * Always returns a string — never `null`.
73+ *
74+ * @param {import("typedoc").Comment | import("typedoc").CommentTag | null | undefined } comment
75+ * @param {number } [headingLevel]
76+ * @returns {string }
77+ */
78+ renderExamples ( comment , headingLevel ) {
79+ const examples =
80+ comment ?. blockTags ?. filter ( ( t ) => t . tag === "@example" ) ?? [ ] ;
7181 if ( ! examples . length ) return "" ;
72- return (
73- "\n\n" +
74- examples
75- . map ( ( tag ) => ctx . helpers . getCommentParts ( tag . content ) . trim ( ) )
76- . join ( "\n\n" )
77- ) ;
82+
83+ const bodies = examples
84+ . map ( ( tag ) => {
85+ const body = ctx . helpers . getCommentParts ( tag . content ) . trim ( ) ;
86+ if ( ! body ) return null ; // skip empty @example tags
87+
88+ if ( headingLevel != null ) {
89+ // Block context (signature / comment partial) → add heading
90+ const prefix = "#" . repeat ( headingLevel + 1 ) ;
91+ const suffix =
92+ examples . length > 1 ? ` ${ examples . indexOf ( tag ) + 1 } ` : "" ;
93+ return `${ prefix } Example${ suffix } \n\n${ body } ` ;
94+ }
95+
96+ // Inline context (typedListItem) → no heading, just body
97+ return body ;
98+ } )
99+ . filter ( Boolean ) ;
100+
101+ return bodies . length ? "\n\n" + bodies . join ( "\n\n" ) : "" ;
78102 } ,
79103} ) ;
0 commit comments