@@ -52,56 +52,60 @@ export default function renderCommand(
5252
5353 const toc : TableOfContentsItem_ [ ] = [ ] ;
5454
55- let about = command . about ! . replaceAll (
56- SUBSEQUENT_ENCAPSULATED_ANSI_RE ,
57- function (
58- _ ,
59- _opening1 ,
60- text1 ,
61- _closing1 ,
62- space ,
63- opening2 ,
64- text2 ,
65- closing2 ,
66- ) {
67- return `${ opening2 } ${ text1 } ${ space } ${ text2 } ${ closing2 } ` ;
68- } ,
69- ) . replaceAll ( SUBSEQUENT_ANSI_RE , "" ) ;
70- let aboutLines = about . split ( "\n" ) ;
71- const aboutLinesReadMoreIndex = aboutLines . findLastIndex ( ( line ) =>
72- line . toLowerCase ( ) . replaceAll ( ANSI_RE , "" ) . trim ( ) . startsWith ( "read more:" )
73- ) ;
74- if ( aboutLinesReadMoreIndex !== - 1 ) {
75- aboutLines = aboutLines . slice ( 0 , aboutLinesReadMoreIndex ) ;
76- }
77-
78- about = aboutLines . join ( "\n" ) . replaceAll (
79- ENCAPSULATED_ANSI_RE ,
80- ( _ , opening , text , _closing , offset , string ) => {
81- if ( opening === "\u001b[32m" ) { // green, used as heading
82- return `### ${ text } ` ;
83- } else if (
84- opening === "\u001b[38;5;245m" || opening === "\u001b[36m" ||
85- opening === "\u001b[1m" || opening === "\u001b[22m"
86- ) { // gray and cyan used for code and snippets, and we treat yellow and bold as well as such
87- const lines = string . split ( "\n" ) ;
88- let line = "" ;
89-
90- while ( offset > 0 ) {
91- line = lines . shift ( ) ;
92- offset -= line . length + 1 ;
93- }
55+ // Add null check for command.about
56+ let about = "" ;
57+ if ( command . about ) {
58+ about = command . about . replaceAll (
59+ SUBSEQUENT_ENCAPSULATED_ANSI_RE ,
60+ function (
61+ _ ,
62+ _opening1 ,
63+ text1 ,
64+ _closing1 ,
65+ space ,
66+ opening2 ,
67+ text2 ,
68+ closing2 ,
69+ ) {
70+ return `${ opening2 } ${ text1 } ${ space } ${ text2 } ${ closing2 } ` ;
71+ } ,
72+ ) . replaceAll ( SUBSEQUENT_ANSI_RE , "" ) ;
73+ let aboutLines = about . split ( "\n" ) ;
74+ const aboutLinesReadMoreIndex = aboutLines . findLastIndex ( ( line ) =>
75+ line . toLowerCase ( ) . replaceAll ( ANSI_RE , "" ) . trim ( ) . startsWith ( "read more:" )
76+ ) ;
77+ if ( aboutLinesReadMoreIndex !== - 1 ) {
78+ aboutLines = aboutLines . slice ( 0 , aboutLinesReadMoreIndex ) ;
79+ }
9480
95- if ( START_AND_END_ANSI_RE . test ( line . trim ( ) ) ) {
96- return "\n```\n" + text + "\n```\n\n" ;
81+ about = aboutLines . join ( "\n" ) . replaceAll (
82+ ENCAPSULATED_ANSI_RE ,
83+ ( _ , opening , text , _closing , offset , string ) => {
84+ if ( opening === "\u001b[32m" ) { // green, used as heading
85+ return `### ${ text } ` ;
86+ } else if (
87+ opening === "\u001b[38;5;245m" || opening === "\u001b[36m" ||
88+ opening === "\u001b[1m" || opening === "\u001b[22m"
89+ ) { // gray and cyan used for code and snippets, and we treat yellow and bold as well as such
90+ const lines = string . split ( "\n" ) ;
91+ let line = "" ;
92+
93+ while ( offset > 0 ) {
94+ line = lines . shift ( ) ;
95+ offset -= line . length + 1 ;
96+ }
97+
98+ if ( START_AND_END_ANSI_RE . test ( line . trim ( ) ) ) {
99+ return "\n```\n" + text + "\n```\n\n" ;
100+ } else {
101+ return "`" + text + "`" ;
102+ }
97103 } else {
98- return "`" + text + "`" ;
104+ return text ;
99105 }
100- } else {
101- return text ;
102- }
103- } ,
104- ) ;
106+ } ,
107+ ) ;
108+ }
105109
106110 const args = [ ] ;
107111 const options : Record < string , ArgType [ ] > = { } ;
@@ -171,16 +175,19 @@ function renderOption(group: string, arg: ArgType, helpers: Lume.Helpers) {
171175 const id = `${ group } -${ arg . name } ` ;
172176
173177 let docsLink = null ;
174- let help = arg . help . replaceAll ( ANSI_RE , "" ) ;
175- const helpLines = help . split ( "\n" ) ;
176- const helpLinesDocsIndex = helpLines . findLastIndex ( ( line ) =>
177- line . toLowerCase ( )
178- . trim ( )
179- . startsWith ( "docs:" )
180- ) ;
181- if ( helpLinesDocsIndex !== - 1 ) {
182- help = helpLines . slice ( 0 , helpLinesDocsIndex ) . join ( "\n" ) ;
183- docsLink = helpLines [ helpLinesDocsIndex ] . trim ( ) . slice ( "docs:" . length ) ;
178+ // Add null check for arg.help
179+ let help = arg . help ? arg . help . replaceAll ( ANSI_RE , "" ) : "" ;
180+ if ( help ) {
181+ const helpLines = help . split ( "\n" ) ;
182+ const helpLinesDocsIndex = helpLines . findLastIndex ( ( line ) =>
183+ line . toLowerCase ( )
184+ . trim ( )
185+ . startsWith ( "docs:" )
186+ ) ;
187+ if ( helpLinesDocsIndex !== - 1 ) {
188+ help = helpLines . slice ( 0 , helpLinesDocsIndex ) . join ( "\n" ) ;
189+ docsLink = helpLines [ helpLinesDocsIndex ] . trim ( ) . slice ( "docs:" . length ) ;
190+ }
184191 }
185192
186193 return (
0 commit comments