Skip to content

Commit 46c016b

Browse files
Fix online help (#791)
1 parent aa9a2bb commit 46c016b

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/MamlWriter/MamlHelpers.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,19 @@ public static HelpItems ConvertCommandHelpToMamlHelpItems(List<CommandHelp> comm
4040
var helpItems = new HelpItems();
4141
foreach(var command in commandHelp)
4242
{
43-
helpItems.Commands.Add(ConvertCommandHelpToMamlCommand(command));
43+
if (command is not null)
44+
{
45+
var onlineHelpUri = command.Metadata?["HelpUri"]?.ToString();
46+
47+
var mamlCommand = ConvertCommandHelpToMamlCommand(command);
48+
49+
if (onlineHelpUri is not null)
50+
{
51+
mamlCommand.RelatedLinks.Insert(0, new NavigationLink { LinkText = "Online Version", Uri = onlineHelpUri });
52+
}
53+
54+
helpItems.Commands.Add(mamlCommand);
55+
}
4456
}
4557
return helpItems;
4658
}

test/Pester/ExportMamlCommandHelp.Tests.ps1

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ Describe "Export-MamlCommandHelp tests" {
112112
}
113113

114114
It "Should have the proper number of relatedLinks" {
115-
$xml2.SelectNodes('//command:command', $ns2).Where({$_.details.name -eq "Get-Date"}).relatedLinks.navigationLink.Count | Should -Be 6
115+
$xml2.SelectNodes('//command:command', $ns2).Where({$_.details.name -eq "Get-Date"}).relatedLinks.navigationLink.Count | Should -Be 7
116116
}
117117

118118
It "Should have the same content for the description" {
@@ -135,5 +135,13 @@ Describe "Export-MamlCommandHelp tests" {
135135
$mamlFie = $m | Export-MamlCommandHelp -OutputFolder $outputDirectory -Force
136136
$mamlFie | Should -FileContentMatch '<maml:para>&#x80;</maml:para>'
137137
}
138+
139+
It "Should have online help uri" {
140+
$m = Import-MarkdownCommandHelp -Path (Join-Path $assetDir 'Get-Date.V2.md')
141+
$mamlFile = $m | Export-MamlCommandHelp -OutputFolder "$outputDirectory/helpuri" -Force
142+
$mamlFile | Should -Exist
143+
$maml = Get-Content -Path $mamlFile -Raw
144+
$maml | Should -BeLike '*<command:uri>https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/get-date?view=powershell-7.4&amp;WT.mc_id=ps-gethelp</command:uri>*'
145+
}
138146
}
139147
}

0 commit comments

Comments
 (0)