File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,22 @@ export default (ctx) => ({
3131 return entries . map ( ctx . helpers . typedListItem ) . join ( "\n" ) ;
3232 } ,
3333
34+ renderExamples ( comment , headingLevel ) {
35+ const examples =
36+ comment ?. blockTags ?. filter ( ( t ) => t . tag === "@example" ) ?? [ ] ;
37+ if ( ! examples . length ) return null ;
38+
39+ const prefix = "#" . repeat ( headingLevel + 1 ) ;
40+ return examples
41+ . map ( ( tag , index ) => {
42+ const heading = `${ prefix } Example${ examples . length > 1 ? ` ${ index + 1 } ` : "" } ` ;
43+ const body = ctx . helpers . getCommentParts ( tag . content ) . trim ( ) ;
44+ return body ? `${ heading } \n\n${ body } ` : null ;
45+ } )
46+ . filter ( Boolean )
47+ . join ( "\n\n" ) ;
48+ } ,
49+
3450 stabilityBlockquote ( comment ) {
3551 if ( ! comment ) return null ;
3652
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ export default (ctx) => ({
6060 headingLevel : options . headingLevel ,
6161 showTags : false ,
6262 } ) ,
63+ ctx . helpers . renderExamples ( comment , options . headingLevel ) ,
6364 ]
6465 . filter ( ( x ) => typeof x === "string" || Boolean ( x ) )
6566 . join ( "\n" ) ;
You can’t perform that action at this time.
0 commit comments