Skip to content

Ensure the next header after description is examples while parsing MD #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/MarkdownReader/CommandHelpMarkdownReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ internal static string GetDescriptionFromMarkdown(ParsedMarkdownContent markdown
diagnostics.Add(new DiagnosticMessage( DiagnosticMessageSource.Description, "DESCRIPTION header found", DiagnosticSeverity.Information, "DESCRIPTION", markdownContent.GetTextLine(start)));
markdownContent.Seek(start);
markdownContent.Take();
var end = markdownContent.FindHeader(2, string.Empty);
var end = markdownContent.FindHeader(2, "EXAMPLES");
return markdownContent.GetStringFromAst(end).Trim();
}

Expand Down
10 changes: 10 additions & 0 deletions test/Pester/ImportMarkdownCommandHelp.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -251,4 +251,14 @@ Describe 'Import-MarkdownCommandHelp Tests' {
$ch.Syntax[$offset].ToString() | Should -Be $string
}
}

Context 'Validate Description' {
BeforeAll {
$ch = Import-MarkdownCommandHelp "$PSScriptRoot/assets/Compare-CommandHelp2.md"
}

It "Should handle empty description" {
$ch.Description | Should -BeNullOrEmpty
}
}
}
4 changes: 2 additions & 2 deletions test/Pester/MeasurePlatyPSMarkdown.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Describe "Export-MarkdownModuleFile" {

It "Should identify all the '<fileType>' assets" -TestCases @(
@{ fileType = "unknown"; expectedCount = 2 }
@{ fileType = "CommandHelp"; expectedCount = 39 }
@{ fileType = "CommandHelp"; expectedCount = 40 }
@{ fileType = "ModuleFile"; expectedCount = 14 }
@{ fileType = "V1Schema"; expectedCount = 49 }
@{ fileType = "V2Schema"; expectedCount = 4 }
@{ fileType = "V2Schema"; expectedCount = 5 }
) {
param ($fileType, $expectedCount)
$idents.Where({($_.FileType -band $fileType) -eq $fileType}).Count | Should -Be $expectedCount
Expand Down
114 changes: 114 additions & 0 deletions test/Pester/assets/Compare-CommandHelp2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
---
document type: cmdlet
external help file: Microsoft.PowerShell.PlatyPS.dll-Help.xml
HelpUri: ''
Locale: en-US
Module Name: Microsoft.PowerShell.PlatyPS
ms.date: 03/07/2025
PlatyPS schema version: 2024-05-01
title: Compare-CommandHelp
---

# Compare-CommandHelp

## SYNOPSIS

## SYNTAX

### __AllParameterSets

```
Compare-CommandHelp [-ReferenceCommandHelp] <CommandHelp> [-DifferenceCommandHelp] <CommandHelp>
[-PropertyNamesToExclude <string[]>] [<CommonParameters>]
```

## ALIASES

This cmdlet has the following aliases,

## DESCRIPTION

## EXAMPLES

### Example 1

## PARAMETERS

### -DifferenceCommandHelp

```yaml
Type: Microsoft.PowerShell.PlatyPS.Model.CommandHelp
DefaultValue: ''
SupportsWildcards: false
ParameterValue: []
Aliases: []
ParameterSets:
- Name: (All)
Position: 1
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: true
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
```

### -PropertyNamesToExclude

```yaml
Type: System.String[]
DefaultValue: ''
SupportsWildcards: false
ParameterValue: []
Aliases: []
ParameterSets:
- Name: (All)
Position: Named
IsRequired: false
ValueFromPipeline: false
ValueFromPipelineByPropertyName: false
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
```

### -ReferenceCommandHelp

```yaml
Type: Microsoft.PowerShell.PlatyPS.Model.CommandHelp
DefaultValue: ''
SupportsWildcards: false
ParameterValue: []
Aliases: []
ParameterSets:
- Name: (All)
Position: 0
IsRequired: true
ValueFromPipeline: false
ValueFromPipelineByPropertyName: true
ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''
```

### CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable,
-InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable,
-ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see
[about_CommonParameters](https://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

### Microsoft.PowerShell.PlatyPS.Model.CommandHelp

## OUTPUTS

### System.String

## NOTES

## RELATED LINKS