diff --git a/src/MamlWriter/MamlHelpers.cs b/src/MamlWriter/MamlHelpers.cs index d1c49984..bc9025d7 100644 --- a/src/MamlWriter/MamlHelpers.cs +++ b/src/MamlWriter/MamlHelpers.cs @@ -40,7 +40,19 @@ public static HelpItems ConvertCommandHelpToMamlHelpItems(List comm var helpItems = new HelpItems(); foreach(var command in commandHelp) { - helpItems.Commands.Add(ConvertCommandHelpToMamlCommand(command)); + if (command is not null) + { + var onlineHelpUri = command.Metadata?["HelpUri"]?.ToString(); + + var mamlCommand = ConvertCommandHelpToMamlCommand(command); + + if (onlineHelpUri is not null) + { + mamlCommand.RelatedLinks.Insert(0, new NavigationLink { LinkText = "Online Version", Uri = onlineHelpUri }); + } + + helpItems.Commands.Add(mamlCommand); + } } return helpItems; } diff --git a/test/Pester/ExportMamlCommandHelp.Tests.ps1 b/test/Pester/ExportMamlCommandHelp.Tests.ps1 index 32d1ffb5..619155bc 100644 --- a/test/Pester/ExportMamlCommandHelp.Tests.ps1 +++ b/test/Pester/ExportMamlCommandHelp.Tests.ps1 @@ -112,7 +112,7 @@ Describe "Export-MamlCommandHelp tests" { } It "Should have the proper number of relatedLinks" { - $xml2.SelectNodes('//command:command', $ns2).Where({$_.details.name -eq "Get-Date"}).relatedLinks.navigationLink.Count | Should -Be 6 + $xml2.SelectNodes('//command:command', $ns2).Where({$_.details.name -eq "Get-Date"}).relatedLinks.navigationLink.Count | Should -Be 7 } It "Should have the same content for the description" { @@ -135,5 +135,13 @@ Describe "Export-MamlCommandHelp tests" { $mamlFie = $m | Export-MamlCommandHelp -OutputFolder $outputDirectory -Force $mamlFie | Should -FileContentMatch '' } + + It "Should have online help uri" { + $m = Import-MarkdownCommandHelp -Path (Join-Path $assetDir 'Get-Date.V2.md') + $mamlFile = $m | Export-MamlCommandHelp -OutputFolder "$outputDirectory/helpuri" -Force + $mamlFile | Should -Exist + $maml = Get-Content -Path $mamlFile -Raw + $maml | Should -BeLike '*https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/get-date?view=powershell-7.4&WT.mc_id=ps-gethelp*' + } } }