Skip to content

Commit c505623

Browse files
Improve command markdown output handling
Enhances the script to only include valid Outputs in the table of contents and output sections, skipping malformed or empty output data. Also normalizes example prompts and improves formatting for code blocks and output lines.
1 parent 7dc3fbd commit c505623

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

scripts/generate-command-pages.ps1

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ function New-CommandMarkdown {
145145
$tocItems += '<a href="#optional-parameters">Parameters</a>'
146146
}
147147
}
148-
if ($command.Outputs) {
148+
# Only add Outputs to TOC if it has valid content (not malformed data)
149+
$tocHasValidOutput = $command.Outputs -and
150+
$command.Outputs.Trim() -and
151+
$command.Outputs -notmatch '@\{type=\}'
152+
if ($tocHasValidOutput) {
149153
$tocItems += '<a href="#outputs">Outputs</a>'
150154
}
151155
$null = $markdown.Add('<nav class="command-toc"><span class="toc-label">On this page:</span> ' + ($tocItems -join ' · ') + '</nav>')
@@ -228,17 +232,19 @@ function New-CommandMarkdown {
228232
if ($row -like '*----*') {
229233
$null = $markdown.Add('')
230234
$null = $markdown.Add('##### ' + ($row -replace '-{4,}([^-]*)-{4,}', '$1').Replace('EXAMPLE', 'Example: '))
231-
} elseif (($row -like 'PS C:\>*') -or ($row -like '>>*')) {
235+
} elseif (($row -like '*PS C:\>*') -or ($row -like '*C:\PS>*') -or ($row -like '>>*')) {
232236
if ($inside -eq 0) {
233237
$cleanCode.Clear()
234238
$null = $markdown.Add('')
235239
$null = $markdown.Add('```powershell')
236240
}
237-
# Add formatted line with prompt
238-
$null = $markdown.Add(($row.Trim() -replace 'PS C:\\>\s*', 'PS C:\> '))
241+
# Add formatted line with prompt (normalize C:\PS> to PS C:\>)
242+
$formattedRow = $row.Trim() -replace 'C:\\PS>\s*', 'PS C:\> '
243+
$formattedRow = $formattedRow -replace 'PS C:\\>\s*', 'PS C:\> '
244+
$null = $markdown.Add($formattedRow)
239245

240246
# Collect clean code without prompts
241-
$cleanLine = $row.Trim() -replace '^PS C:\\>\s*', '' -replace '^>>\s*', ''
247+
$cleanLine = $row.Trim() -replace '^C:\\PS>\s*', '' -replace '^PS C:\\>\s*', '' -replace '^>>\s*', ''
242248
if ($cleanLine) {
243249
$null = $cleanCode.Add($cleanLine)
244250
}
@@ -252,7 +258,7 @@ function New-CommandMarkdown {
252258
$null = $markdown.Add('```')
253259
$null = $markdown.Add('')
254260
}
255-
$null = $markdown.Add("$($row.Replace("`n", " `n"))<br>")
261+
$null = $markdown.Add("$($row.Trim().Replace("`n", " `n"))<br>")
256262
}
257263
}
258264

@@ -330,7 +336,12 @@ function New-CommandMarkdown {
330336
}
331337

332338
# Outputs
333-
if ($command.Outputs) {
339+
# Skip malformed output data like "@{type=}" or "returnValue" with no actual content
340+
$hasValidOutput = $command.Outputs -and
341+
$command.Outputs.Trim() -and
342+
$command.Outputs -notmatch '^\s*returnValue\s*-+\s*@\{type=\}\s*$' -and
343+
$command.Outputs -notmatch '@\{type=\}'
344+
if ($hasValidOutput) {
334345
$null = $markdown.Add('<span id="outputs" class="section-anchor"></span>')
335346
$null = $markdown.Add('<h2><a class="anchor-link" href="#outputs"></a><a href="#outputs" class="heading-link">Outputs</a></h2>')
336347
$null = $markdown.Add('')

0 commit comments

Comments
 (0)