PowerShell / platyPS

Write PowerShell External Help in Markdown
MIT License
765 stars 149 forks source link

[Markdown.MAML.Transformer.ModelTransformerVersion2].NodeModelToMamlModel does not process in-line links well #583

Closed jhoneill closed 3 months ago

jhoneill commented 2 years ago

Prerequisites

Steps to reproduce

  1. As a test file I have download the MD help file for Get-Help from. https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/7.2/Microsoft.PowerShell.Core/Get-Help.md
  2. In VS Code I have set a break point on new-externalHelp but the important part is in the function GetMamlModelImpl which has lines $model = $p.ParseString($mdText, $parseMode, $_) (1605 in the .PSM1 file for v 0.14.2 )
    and $maml = $t.NodeModelToMamlModel($model) (1607 in the same file)
  3. After the second line has run examine $model.children[17].spans[8], $model.children[17].spans[9] , and $model.children[17].spans[10] and $maml.description.text
$model.children[17].spans[8]

 Style Text 
 ----- ----
Normal parameter, such as: `Get-Help Get-Process -Online`. To read all the PowerShell documentation, see the Microsoft Docs

$model.children[17].spans[9]

Uri         Text
---         ----
/powershell PowerShell Documentation

$model.children[17].spans[10] | ft -wrap

 Style Text
 ----- ----
Normal .
       If you type `Get-Help` followed by the exact name of a help article, 

In the middle of the maml text we can find

... parameter, such as: `Get-Help Get-Process -Online`. To read all the PowerShell documentation, see the Microsoft Docs PowerShell Documentation (/powershell).
If you type `Get-Help` followed by the exact name of a help article,  ...  

The link makes no sense in maml because it is a relative path to the online help page, and the text to highlight as a link is lost

Expected behavior

EITHER relative links are removed from the MAML, as they make no sense 
OR   relative links are converted to absolute ones (using the external help link from the meta data at the start of the mark down file) and the text to use as a hyperlink is identified.

Actual behavior

Get-Help get-Help includes text like this 

To read all the PowerShell documentation, see the Microsoft Docs PowerShell Documentation (/powershell).

Error details

No error message

Environment data

Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     0.14.2                platyPS                             Desk      {New-MarkdownHelp, Get-MarkdownMetadata, New-ExternalHelp, New-YamlHelp}

Name                           Value
----                           -----
PSVersion                      7.2.6
PSEdition                      Core
GitCommitId                    7.2.6
OS                             Microsoft Windows 10.0.22000
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

sdwheeler commented 3 months ago

This is fixed in Microsoft.PowerShell.PlatyPS v1.