Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Update markdown help #607

Open
wants to merge 3 commits into
base: v2
Choose a base branch
from
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
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
{
"files.exclude": {
"out/**": true
}
},
"sarif-viewer.connectToGithubCodeScanning": "off"
}
32 changes: 2 additions & 30 deletions src/GetMarkdownMetadataCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ protected override void ProcessRecord()
{
if (Markdown is not null)
{
DeserializeAndWrite(GetMarkdownMetadataHeaderReader(Markdown));
DeserializeAndWrite(MarkdownUtilities.GetMarkdownMetadataHeaderReader(Markdown));
}
}
else if (string.Equals(this.ParameterSetName, "FromPath", StringComparison.OrdinalIgnoreCase))
Expand All @@ -55,7 +55,7 @@ protected override void ProcessRecord()

foreach (var resolvedPath in resolvedPaths)
{
DeserializeAndWrite(GetMarkdownMetadataHeaderReader(File.ReadAllText(resolvedPath.Path)));
DeserializeAndWrite(MarkdownUtilities.GetMarkdownMetadataHeaderReader(File.ReadAllText(resolvedPath.Path)));
}
}
}
Expand All @@ -68,33 +68,5 @@ private void DeserializeAndWrite(string headerContent)
var deserializer = new YamlDotNet.Serialization.DeserializerBuilder().Build();
WriteObject(deserializer.Deserialize(stringReader));
}

private string GetMarkdownMetadataHeaderReader(string content)
{
if (string.IsNullOrEmpty(content))
{
return string.Empty;
}

var mdAst = Markdig.Markdown.Parse(content);

if (mdAst.Count < 2)
{
return string.Empty;
}

if (mdAst[0] is Markdig.Syntax.ThematicBreakBlock)
{
if (mdAst[1] is Markdig.Syntax.HeadingBlock metadata)
{
if (metadata.Inline?.FirstChild is Markdig.Syntax.Inlines.LiteralInline metadataText)
{
return metadataText.Content.Text;
}
}
}

return string.Empty;
}
}
}
39 changes: 39 additions & 0 deletions src/MarkdownUtilities.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.PowerShell.PlatyPS
{
internal class MarkdownUtilities
{
internal static string GetMarkdownMetadataHeaderReader(string content)
{
if (string.IsNullOrEmpty(content))
{
return string.Empty;
}

var mdAst = Markdig.Markdown.Parse(content);

if (mdAst.Count < 2)
{
return string.Empty;
}

if (mdAst[0] is Markdig.Syntax.ThematicBreakBlock)
{
if (mdAst[1] is Markdig.Syntax.HeadingBlock metadata)
{
if (metadata.Inline?.FirstChild is Markdig.Syntax.Inlines.LiteralInline metadataText)
{
return metadataText.Content.Text;
}
}
}

return string.Empty;
}
}
}
4 changes: 3 additions & 1 deletion src/Microsoft.PowerShell.PlatyPS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
<LangVersion>latest</LangVersion>
<HighEntropyVA>true</HighEntropyVA>
<Nullable>enable</Nullable>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Markdig.Signed" Version="[0.18.3]" />
<PackageReference Include="Markdig.Signed" Version="0.30.4" />
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="YamlDotNet" Version="11.0.1" />
Expand Down
2 changes: 2 additions & 0 deletions src/Model/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ internal static class Constants
internal const string ModuleGuidHeaderTemplate = "Module Guid: {0}";
internal const string FillInGuid = "XXXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX";
internal const string LocaleEnUs = "en-US";
internal const char Comma = ',';
internal const string CommonParametersHeader = "CommonParameters";
internal static readonly List<string> EmptyStringList = new();
internal static readonly char DirectorySeparator = System.IO.Path.DirectorySeparatorChar;

Expand Down
1 change: 1 addition & 0 deletions src/NewMarkownHelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public sealed class NewMarkdownHelpCommand : PSCmdlet
[Parameter(ParameterSetName = "FromMaml")]
public string? ModulePagePath { get; set; }

[Parameter()]
public SwitchParameter ExcludeDontShow { get; set; }

#endregion
Expand Down
Loading