@@ -105,4 +105,82 @@ describe('markdown output: plugin-auth and user', () => {
105105 expect ( md ) . to . be . a ( 'string' ) ;
106106 // Verify the file exists at the unsuffixed path (the load above would throw if not)
107107 } ) ;
108+
109+ it ( 'escapes HTML entities in descriptions' , ( ) => {
110+ const md = loadMdFile ( join ( 'org' , 'cli_reference_org_create_user.md' ) ) ;
111+ // If there are any < or > characters in descriptions, they should be escaped
112+ const lines = md . split ( '\n' ) ;
113+ for ( const line of lines ) {
114+ // Skip code blocks and HTML tags we intentionally create
115+ if ( line . includes ( '```' ) || line . startsWith ( '<ul>' ) || line . startsWith ( '<li>' ) || line . startsWith ( ':::' ) ) {
116+ continue ;
117+ }
118+ // Check that raw < and > are not present (they should be < and >)
119+ const textOutsideCode = line . replace ( / ` [ ^ ` ] + ` / g, '' ) ;
120+ if ( textOutsideCode . includes ( '<' ) || textOutsideCode . includes ( '>' ) ) {
121+ // Allow markdown links and already-escaped entities
122+ if (
123+ ! textOutsideCode . includes ( '<' ) &&
124+ ! textOutsideCode . includes ( '>' ) &&
125+ ! textOutsideCode . includes ( '[' ) &&
126+ ! textOutsideCode . includes ( '(http' )
127+ ) {
128+ expect . fail ( `Found unescaped < or > in line: ${ line } ` ) ;
129+ }
130+ }
131+ }
132+ } ) ;
133+
134+ it ( 'normalizes whitespace consistently' , ( ) => {
135+ const md = loadMdFile ( join ( 'org' , 'cli_reference_org_login_jwt.md' ) ) ;
136+ // Check that there are no double spaces in descriptions
137+ const lines = md . split ( '\n' ) ;
138+ for ( const line of lines ) {
139+ // Skip code blocks
140+ if ( line . includes ( '```' ) ) continue ;
141+ // Check for multiple consecutive spaces (except in markdown table separators)
142+ if ( line . includes ( ' ' ) && ! line . includes ( '---' ) && ! line . includes ( '|' ) ) {
143+ expect . fail ( `Found multiple consecutive spaces in line: ${ line } ` ) ;
144+ }
145+ }
146+ } ) ;
147+
148+ it ( 'removes leading $ from shell examples' , ( ) => {
149+ const md = loadMdFile ( join ( 'org' , 'cli_reference_org_login_jwt.md' ) ) ;
150+ // Shell examples should not have leading $ prompts
151+ const shellBlocks = md . match ( / ` ` ` s h e l l \n ( [ ^ ` ] + ) ` ` ` / g) ;
152+ if ( shellBlocks ) {
153+ for ( const block of shellBlocks ) {
154+ const commands = block . split ( '\n' ) . slice ( 1 , - 1 ) ;
155+ for ( const cmd of commands ) {
156+ if ( cmd . trim ( ) . startsWith ( '$' ) ) {
157+ expect . fail ( `Found leading $ in shell example: ${ cmd } ` ) ;
158+ }
159+ }
160+ }
161+ }
162+ } ) ;
163+
164+ it ( 'includes state labels for beta/preview/pilot commands' , ( ) => {
165+ // Test with a command that has a state if one exists
166+ const md = loadMdFile ( join ( 'org' , 'cli_reference_org_login_jwt.md' ) ) ;
167+ // This test verifies the format - actual state depends on the command
168+ expect ( md ) . to . be . a ( 'string' ) ;
169+ } ) ;
170+
171+ it ( 'formats flag descriptions as markdown tables with proper escaping' , ( ) => {
172+ const md = loadMdFile ( join ( 'org' , 'cli_reference_org_create_user.md' ) ) ;
173+ if ( md . includes ( '## Flags' ) ) {
174+ // Check that pipe characters in flag descriptions are escaped
175+ const tableLines = md . split ( '\n' ) . filter ( ( line ) => line . includes ( '|' ) ) ;
176+ for ( const line of tableLines ) {
177+ // Count pipes - should have exactly 4 for a 3-column table (| col1 | col2 | col3 |)
178+ const pipeCount = ( line . match ( / \| / g) ?? [ ] ) . length ;
179+ if ( line . includes ( '---' ) ) continue ; // Skip separator line
180+ // Allow for | escaped pipes in content
181+ const escapedPipes = ( line . match ( / & # 1 2 4 ; / g) ?? [ ] ) . length ;
182+ expect ( pipeCount - escapedPipes ) . to . be . at . least ( 4 ) ;
183+ }
184+ }
185+ } ) ;
108186} ) ;
0 commit comments