Skip to content
Open
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
10 changes: 10 additions & 0 deletions src/MamlWriter/MamlConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,15 @@ internal static partial class Constants
internal const string MamlLinkTextTag = "maml:linkText";
internal const string MamlUriTag = "maml:uri";
internal const string MamlFileExtensionSuffix = "-help.xml";
// Legacy compatibility:
// Older versions of platyPS (prior to 1.0.2) emitted `<command:url>`
// in Export-MamlCommandHelp, and some existing MAML help files still
// use `<command:uri>`. PowerShell’s built-in MAML reader accepts both
// because it matches only the local-name `uri`.
//
// Import-MamlHelp must continue to support `<command:uri>` for
// compatibility with legacy MAML content. This constant can be removed
// once all supported MAML formats use `<maml:uri>` exclusively.
internal const string MamlCommandUriTag = "command:uri";
}
}
28 changes: 18 additions & 10 deletions src/Transform/TransformMaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,26 +137,34 @@ private Collection<Links> ReadRelatedLinks(XmlReader reader)
{
do
{
var subTree = reader.ReadSubtree();

string? linkText = null;
string? uri = null;

if (reader.ReadToFollowing(Constants.MamlLinkTextTag))
while (subTree.Read())
{
linkText = reader.ReadElementContentAsString();
}

if (reader.ReadToFollowing(Constants.MamlUriTag))
{
uri = reader.ReadElementContentAsString();
switch (subTree.Name)
{
case Constants.MamlLinkTextTag:
linkText = reader.ReadElementContentAsString();
continue;
case Constants.MamlUriTag:
case Constants.MamlCommandUriTag:
// Support `<command:uri>` for legacy MAML compatibility.
// PowerShell’s built-in MAML reader accepts both `<maml:uri>` and
// `<command:uri>` (matching only the local-name `uri`), so platyPS
// must do the same. This branch can be removed once legacy MAML
// formats are no longer supported.
uri = reader.ReadElementContentAsString();
continue;
}
}

if (linkText != null && uri != null)
{
relatedLinks.Add(new Links(uri, linkText));
}

reader.ReadEndElement();

} while (reader.ReadToNextSibling(Constants.MamlNavigationLinkTag));
}
}
Expand Down
10 changes: 9 additions & 1 deletion test/Pester/ImportMamlHelp.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

Describe "Import-YamlHelp tests" {
Describe "Import-MamlHelp tests" {
Context "Basic tests" {
BeforeAll {
$mamlFile = "${PSScriptRoot}/assets/Microsoft.PowerShell.Commands.Utility.dll-Help.xml"
Expand Down Expand Up @@ -97,5 +97,13 @@ Describe "Import-YamlHelp tests" {
$values | Should -BeExactly $expectedValues
}
}

Context 'Load legacy' {
It 'load <command:uri> in related links' {
$mamlFile = "${PSScriptRoot}/assets/legacy-maml/command:uri-in-related-links.xml"
$importedCmd = Import-MamlHelp $mamlFile
$importedCmd.RelatedLinks[0].Uri | Should -Be "https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/get-date?view=powershell-7.4&WT.mc_id=ps-gethelp"
}
}
}
}
36 changes: 36 additions & 0 deletions test/Pester/assets/legacy-maml/command:uri-in-related-links.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<helpItems xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10" schema="maml" xmlns="http://msh">
<command:command>
<command:details>
<command:name>Get-Date</command:name>
<maml:description>
<maml:para>Gets the current date and time.</maml:para>
</maml:description>
<command:verb>Get</command:verb>
<command:noun>Date</command:noun>
</command:details>
<maml:description>
<maml:para />
</maml:description>
<command:syntax>
<command:syntaxItem>
<maml:name>Get-Date</maml:name>
</command:syntaxItem>
</command:syntax>
<command:parameters />
<command:inputTypes />
<command:returnValues />
<maml:alertSet>
<maml:alert>
<maml:para />
</maml:alert>
</maml:alertSet>
<command:examples />
<command:relatedLinks>
<maml:navigationLink>
<maml:linkText>Online Version</maml:linkText>
<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>
</maml:navigationLink>
</command:relatedLinks>
</command:command>
</helpItems>