PlatyPS 希望 Markdown 文件遵循特定的结构。 如果结构不正确,则转换为 MAML 格式可能会失败,或者 MAML 内容可能不完整。 完成 Markdown 文件的编辑后,应对其进行测试以确保结构正确。
测试 Markdown 命令帮助文件的最佳方法是导入文件并检查生成的对象。 以下示例导入命令的 Measure-PlatyPSMarkdown Markdown 文件,并将生成的对象存储在变量中 $cmdHelp 。 该 Format-List * 命令显示对象的所有属性。 检查属性以确保它们包含预期的内容。
$cmdFilePath = '.\Microsoft.PowerShell.PlatyPS\Measure-PlatyPSMarkdown.md'
$cmdHelp = Import-MarkdownCommandHelp -Path $cmdFilePath
$cmdHelp | Format-List *
Metadata : {[document type, cmdlet], [external help file, WidgetModule-Help.xml],
[HelpUri, ], [Locale, en-US]…}
Locale : en-US
ModuleGuid :
ExternalHelpFile : WidgetModule-Help.xml
OnlineVersionUrl :
SchemaVersion : 2024-05-01
ModuleName : WidgetModule
Title : Get-Widget
Synopsis : Gets one or more widgets based on specified criteria.
Syntax : {Get-Widget [-Name] <string> [-Color <ConsoleColor>] [-Size <int>]
[-Detailed] [<CommonParameters>]}
AliasHeaderFound : True
Aliases :
Description : Gets one or more widgets from the system. You can filter the results
by specifying the widget's name, color, or size. Use the -Detailed
switch to retrieve additional information about each widget.
each widget.
Examples : {Microsoft.PowerShell.PlatyPS.Model.Example}
Parameters : {Color, Detailed, Name, Size}
Inputs : {System.String}
Outputs : {Widget}
Notes :
RelatedLinks : {Microsoft.PowerShell.PlatyPS.Model.Links}
HasCmdletBinding : True
HasWorkflowCommonParameters : False
Diagnostics : Microsoft.PowerShell.PlatyPS.Model.Diagnostics
还 $cmdHelp 包含一个 Diagnostics 属性,其中包含有关 Markdown 文件的任何结构问题的信息。 查看诊断信息并更正 Markdown 文件中的任何问题。
$cmdHelp.Diagnostics.Messages
“ 严重性 ”列指示问题的严重性。 应调查和纠正警告和错误。
Source Severity Message Identifier
------ -------- ------- ----------
Metadata Information {Metadata} found 'external help …
Metadata Information {Metadata} found 'Locale'
Metadata Information {Metadata} found 'Module Name'
Metadata Information {Metadata} found 'ms.date'
Metadata Information {Metadata} found 'HelpUri'
Metadata Information {Metadata} found 'PlatyPS schema…
Metadata Information {Metadata} found 'title'
General Information {CmdletBinding is present} GetCmdletBindingState
General Information {Workflow parameters not present} GetWorkflowCommonPara…
Synopsis Information {SYNOPSIS found}
Syntax Information {Syntax found} Get-Widget [-Name] <s…
Alias Information {ALIASES header found} alias header is AST 8
Alias Information {Alias string length} alias string length: 0
Description Information {DESCRIPTION header found} DESCRIPTION
Example Information {EXAMPLES header found} 1 examples found
Parameter Information {Parameters} 4 parameters found
Parameter Information {Color found} Version 2 metadata fo…
Parameter Information {Detailed found} Version 2 metadata fo…
Parameter Information {Name found} Version 2 metadata fo…
Parameter Information {Size found} Version 2 metadata fo…
Parameter Information {CommonParameters found} GetParameters
Inputs Information {GetInput} 1 items found
Outputs Information {GetOutput} 1 items found
Notes Warning {Notes content not found} GetNotes
Links Information {Links found} GetRelatedLinks
Links Information {Found related links as unordered list.}
Links Information {adding link [All about widgets](https://docs…
Links Information {Links found} 1 links found
有关 Markdown 文件的预期结构的详细信息,请参阅 编辑 Markdown 帮助文件。
您可以使用命令 Import-MarkdownModuleFile 以类似的方式测试模块 Markdown 文件。 例如:
$modFilePath = '.\Microsoft.PowerShell.PlatyPS\Microsoft.PowerShell.PlatyPS.md'
$mod = Import-MarkdownModuleFile -Path $modFilePath
$mod.Diagnostics.Messages
Source Severity Message Identifier
------ -------- ------- ----------
ModuleFileTitle Information {Title WidgetModule Module… GetModuleFileTitle…
Metadata Information {found guid 8bc631f3-e82e-… GetMetadata
Metadata Information {found module name WidgetM… GetMetadata
Metadata Information {locale set to en-US} GetMetadata
ModuleFileDescription Information {Module description found} GetModuleFileDescr…
ModuleFileCommand Information {command Get-Widget found} GetModuleFileComma…