@@ -28,6 +28,7 @@ type ParsedExample = {
2828export class MarkdownCommand extends MarkdownBase {
2929 private flags : Dictionary < FlagInfo > ;
3030 private commandMeta : Record < string , unknown > ;
31+ private binary : string ;
3132 private commandName : string ;
3233 private summary : string | undefined ;
3334 private help : string [ ] ;
@@ -57,15 +58,14 @@ export class MarkdownCommand extends MarkdownBase {
5758
5859 this . flags = ensureObject ( command . flags ) ;
5960 this . commandMeta = commandMeta ;
60- const binary = readBinary ( this . commandMeta ) ;
61+ this . binary = readBinary ( this . commandMeta ) ;
6162
6263 this . summary = punctuate ( command . summary ) ;
63- // commandName is the bare command ID used for template variable replacement (e.g. "agent activate")
64- // commandNameForDisplay is the full invocation shown in headings (e.g. "sf agent activate")
64+ // commandName is the bare command ID with colons replaced by the topic separator (e.g. "agent activate")
6565 this . commandName = command . id . replace ( / : / g, asString ( this . commandMeta . topicSeparator , ' ' ) ) ;
6666
6767 const description = command . description
68- ? replaceConfigVariables ( command . description , binary , this . commandName )
68+ ? replaceConfigVariables ( command . description , this . binary , this . commandName )
6969 : undefined ;
7070
7171 this . help = formatParagraphs ( description ) ;
@@ -82,21 +82,20 @@ export class MarkdownCommand extends MarkdownBase {
8282 commands = [ example . command ] ;
8383 }
8484 return {
85- description : replaceConfigVariables ( desc ?? '' , binary , this . commandName ) ,
86- commands : commands . map ( ( cmd ) => replaceConfigVariables ( cmd , binary , this . commandName ) ) ,
85+ description : replaceConfigVariables ( desc ?? '' , this . binary , this . commandName ) ,
86+ commands : commands . map ( ( cmd ) => replaceConfigVariables ( cmd , this . binary , this . commandName ) ) ,
8787 } ;
8888 } ) ;
8989
9090 this . state = command . state ?? this . commandMeta . state ;
91- this . deprecated = ( command . deprecated as boolean ) ?? this . state === 'deprecated' ?? false ;
91+ this . deprecated = Boolean ( command . deprecated ) || this . state === 'deprecated' ;
9292 const dep = command . deprecated ;
9393 this . deprecationDetails = dep && typeof dep === 'object' ? ( dep as { version ?: string ; to ?: string } ) : null ;
9494 this . aliases = command . aliases ?? [ ] ;
9595 }
9696
9797 protected async generate ( ) : Promise < string > {
98- const binary = readBinary ( this . commandMeta ) ;
99- const parameters = await buildCommandParameters ( this . commandName , binary , this . flags ) ;
98+ const parameters = await buildCommandParameters ( this . commandName , this . binary , this . flags ) ;
10099
101100 const lines : string [ ] = [ ] ;
102101
@@ -123,7 +122,7 @@ export class MarkdownCommand extends MarkdownBase {
123122 if ( this . help . length > 0 ) {
124123 lines . push ( `## Description for ${ this . commandName } ` ) ;
125124 lines . push ( '' ) ;
126- for ( const paragraph of convertHyphenListsToMarkdown ( this . help . map ( ( p ) => escapeForMarkdown ( p ) ) ) ) {
125+ for ( const paragraph of convertBulletListsToHtml ( this . help . map ( ( p ) => escapeForMarkdown ( p ) ) ) ) {
127126 lines . push ( paragraph ) ;
128127 lines . push ( '' ) ;
129128 }
@@ -192,17 +191,30 @@ function escapeForMarkdown(text: string): string {
192191 return result ;
193192}
194193
195- function convertHyphenListsToMarkdown ( paragraphs : string [ ] ) : string [ ] {
194+ /**
195+ * Converts bullet list paragraphs to HTML <ul>/<li> tags for compact rendering in markdown.
196+ * Strips leading whitespace from bullets to prevent code block rendering.
197+ *
198+ * @param paragraphs - Array of paragraph strings, some may be bullet items
199+ * @returns Array where consecutive bullets are converted to a single HTML <ul> string
200+ */
201+ function convertBulletListsToHtml ( paragraphs : string [ ] ) : string [ ] {
196202 const result : string [ ] = [ ] ;
197203 let i = 0 ;
198204 while ( i < paragraphs . length ) {
199- if ( paragraphs [ i ] . startsWith ( '- ' ) || paragraphs [ i ] . startsWith ( '* ' ) ) {
205+ const trimmed = paragraphs [ i ] . trimStart ( ) ;
206+ if ( trimmed . startsWith ( '- ' ) || trimmed . startsWith ( '* ' ) ) {
200207 // Collect consecutive list items and render as HTML bullet list
201208 const items : string [ ] = [ ] ;
202- while ( i < paragraphs . length && ( paragraphs [ i ] . startsWith ( '- ' ) || paragraphs [ i ] . startsWith ( '* ' ) ) ) {
203- // Remove the leading "- " or "* " and wrap in <li>
204- items . push ( `<li>${ paragraphs [ i ] . substring ( 2 ) } </li>` ) ;
205- i ++ ;
209+ while ( i < paragraphs . length ) {
210+ const itemTrimmed = paragraphs [ i ] . trimStart ( ) ;
211+ if ( itemTrimmed . startsWith ( '- ' ) || itemTrimmed . startsWith ( '* ' ) ) {
212+ // Remove the bullet marker (- or *) and wrap in <li>
213+ items . push ( `<li>${ itemTrimmed . substring ( 2 ) } </li>` ) ;
214+ i ++ ;
215+ } else {
216+ break ;
217+ }
206218 }
207219 // Wrap all items in <ul> tags
208220 result . push ( `<ul>${ items . join ( '' ) } </ul>` ) ;
@@ -274,7 +286,7 @@ function renderFlagDescription(param: CommandParameterData): string {
274286 }
275287 if ( param . defaultFlagValue ) metadataParts . push ( `**Default value:** \`${ param . defaultFlagValue } \`` ) ;
276288
277- const desc = convertHyphenListsToMarkdown (
289+ const desc = convertBulletListsToHtml (
278290 param . description . map ( ( p ) => escapeForMarkdown ( p . replace ( / \| / g, '|' ) ) )
279291 ) . join ( '<br><br>' ) ;
280292
0 commit comments