Skip to content

Commit 33b90b4

Browse files
Allow front matter metadata to have list of Aliases (#730)
1 parent 2e4ae59 commit 33b90b4

File tree

5 files changed

+2213
-2
lines changed

5 files changed

+2213
-2
lines changed

src/MarkdownReader/CommandHelpMarkdownReader.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,38 @@ internal static CommandHelp GetCommandHelpFromMarkdown(ParsedMarkdownContent mar
351351
return ConvertTextToOrderedDictionary(metadataAsParagraph.Content.Text);
352352
}
353353
}
354+
else if (ast[2] is Markdig.Syntax.ListBlock && ast[1] is ParagraphBlock paragraphWithList)
355+
{
356+
List<string> listItems = new();
357+
358+
if (ast[2] is Markdig.Syntax.ListBlock listBlock)
359+
{
360+
foreach (var listItem in listBlock)
361+
{
362+
if (listItem is ListItemBlock listItemBlock)
363+
{
364+
if (listItemBlock is ContainerBlock containerBlock)
365+
{
366+
if (containerBlock.LastChild is ParagraphBlock paragraphListItem)
367+
{
368+
if (paragraphListItem.Inline?.FirstChild is LiteralInline listItemText)
369+
{
370+
listItems.Add(listItemText.Content.ToString().Trim());
371+
}
372+
}
373+
}
374+
}
375+
}
376+
}
377+
378+
if (paragraphWithList.Inline?.FirstChild is LiteralInline metadataAsParagraph)
379+
{
380+
var metadataDictionary = ConvertTextToOrderedDictionary(metadataAsParagraph.Content.Text);
381+
// update the metadata dictionary with the list items of aliases
382+
metadataDictionary["aliases"] = listItems;
383+
return metadataDictionary;
384+
}
385+
}
354386
}
355387

356388
return null;

test/Pester/ImportMarkdownCommandHelp.Tests.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,22 @@ Describe 'Import-MarkdownCommandHelp Tests' {
4343
$metadata[$name] | Should -Be $expectedValue
4444

4545
}
46+
47+
It 'Should be able to read metata with alias as list' {
48+
$result = Import-MarkdownCommandHelp -Path "$assetdir/Get-ChildItem-WithListAliases.md"
49+
$result.Metadata.aliases.Count | Should -Be 3
50+
$result.Metadata.aliases[0] | Should -Be "dir"
51+
$result.Metadata.aliases[1] | Should -Be "ls"
52+
$result.Metadata.aliases[2] | Should -Be "gci"
53+
}
54+
55+
It 'Should be able to read metata with alias as string' {
56+
$result = Import-MarkdownCommandHelp -Path "$assetdir/Get-ChildItem-WithStringAliases.md"
57+
$result.Metadata.aliases.Count | Should -Be 3
58+
$result.Metadata.aliases[0] | Should -Be "dir"
59+
$result.Metadata.aliases[1] | Should -Be "ls"
60+
$result.Metadata.aliases[2] | Should -Be "gci"
61+
}
4662
}
4763

4864
Context "Validate Aliases" {

test/Pester/MeasurePlatyPSMarkdown.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Describe "Export-MarkdownModuleFile" {
1313

1414
It "Should identify all the '<fileType>' assets" -TestCases @(
1515
@{ fileType = "unknown"; expectedCount = 2 }
16-
@{ fileType = "CommandHelp"; expectedCount = 35 }
16+
@{ fileType = "CommandHelp"; expectedCount = 37 }
1717
@{ fileType = "ModuleFile"; expectedCount = 14 }
18-
@{ fileType = "V1Schema"; expectedCount = 45 }
18+
@{ fileType = "V1Schema"; expectedCount = 47 }
1919
@{ fileType = "V2Schema"; expectedCount = 4 }
2020
) {
2121
param ($fileType, $expectedCount)

0 commit comments

Comments
 (0)