@@ -53,22 +53,38 @@ function* generateMarkdown(lines: string[]) {
5353 const bodyRegex = / ^ ( .* ) / ;
5454 const defaultValuesRegex = / ^ \[ ( d e f a u l t | p o s s i b l e v a l u e s | e n v ) : ( .* ) \] $ / ;
5555
56- const markers : { [ l : string ] : number } = { } ;
57- for ( const [ i , line ] of lines . entries ( ) ) {
58- const match = line . match ( optionRegex ) ;
59- if ( match ) {
60- markers [ `#${ match [ 0 ] . trim ( ) } ` ] = i + 1 ;
61- }
62- }
56+ let match ;
57+ for ( const line of lines ) {
58+ if ( line . match ( usageRegex ) ) {
59+ yield '```' ;
60+ yield line ;
61+ yield '```' ;
62+
63+ } else if ( line . match ( headingRegex ) ) {
64+ yield "## " + escapeMarkdown ( line . replace ( / : $ / , '' ) ) ;
65+
66+ } else if ( match = line . match ( optionRegex ) ) {
67+ const option = escapeMarkdown ( match [ 0 ] ) . trim ( ) ;
68+ const longOption = line . replace ( / - [ ^ - ] , / , '' ) ;
69+ yield `### ${ option } ` ;
70+ yield '' ;
71+ yield '```bash' ;
72+ yield `lychee ${ longOption . trimStart ( ) } ` ;
73+ yield '```' ;
74+
75+ } else if ( match = line . match ( bodyRegex ) ) {
76+ const line = match [ 1 ] ;
77+ if ( match = line . match ( defaultValuesRegex ) ) {
78+ yield `**${ match [ 1 ] } **: ${ match [ 2 ] } ` ;
79+ yield '' ;
80+ } else {
81+ yield ' ' + line ;
82+ }
6383
64- for ( const line of Object . keys ( markers ) ) {
65- yield '### ' + line . replace ( '#' , '' ) ;
66- yield '' ;
84+ } else {
85+ yield line ;
86+ }
6787 }
68-
69- yield '```text ' + Object . entries ( markers ) . map ( ( [ l , i ] ) => JSON . stringify ( { [ l ] : i } ) ) . join ( ' ' )
70- yield * lines ;
71- yield '```' ;
7288}
7389
7490export async function generateCliOptionsMarkdown ( ) {
@@ -78,10 +94,10 @@ export async function generateCliOptionsMarkdown() {
7894 const rawUsageText = extractHelpFromReadme ( await readme . text ( ) ) ;
7995 const usageText = [ ...generateMarkdown ( splitLines ( rawUsageText ) ) ] . join ( "\n" ) ;
8096
81- // assert(usageText.match('\n## Options\n'), 'options heading missing, check headingRegex');
82- // assert(usageText.match('\n### --dump\n'), '--dump heading missing, check optionRegex');
83- // assert(usageText.match('\n### --root-dir\n'), '--root-dir heading missing, check optionRegex');
84- // assert(usageText.match('\n Inputs for link checking'), 'expected body text missing, check bodyRegex');
97+ assert ( usageText . match ( '\n## Options\n' ) , 'options heading missing, check headingRegex' ) ;
98+ assert ( usageText . match ( '\n### --dump\n' ) , '--dump heading missing, check optionRegex' ) ;
99+ assert ( usageText . match ( '\n### --root-dir\n' ) , '--root-dir heading missing, check optionRegex' ) ;
100+ assert ( usageText . match ( '\n Inputs for link checking' ) , 'expected body text missing, check bodyRegex' ) ;
85101
86102 return usageText ;
87103}
0 commit comments