diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertFromMarkdownCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertFromMarkdownCommand.cs index a2592d9bf1..b5698603a0 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertFromMarkdownCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ConvertFromMarkdownCommand.cs @@ -2,12 +2,12 @@ // Licensed under the MIT License. using System; -using System.IO; -using System.Threading.Tasks; -using System.Collections.ObjectModel; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; using System.Management.Automation; using System.Management.Automation.Internal; +using System.Threading.Tasks; using Microsoft.PowerShell.MarkdownRender; using Dbg = System.Management.Automation; @@ -20,36 +20,35 @@ namespace Microsoft.PowerShell.Commands [Cmdlet( VerbsData.ConvertFrom, "Markdown", DefaultParameterSetName = PathParameterSet, - HelpUri = "TBD" - )] + HelpUri = "TBD")] [OutputType(typeof(Microsoft.PowerShell.MarkdownRender.MarkdownInfo))] public class ConvertFromMarkdownCommand : PSCmdlet { /// - /// Path to the file to convert from Markdown to MarkdownInfo. + /// Gets or sets path to the file to convert from markdown to MarkdownInfo. /// [ValidateNotNullOrEmpty] [Parameter(ParameterSetName = PathParameterSet, Mandatory = true)] public string[] Path { get; set; } /// - /// Path to the file to convert from Markdown to MarkdownInfo. + /// Gets or sets the path to the file to convert from markdown to MarkdownInfo. /// [ValidateNotNullOrEmpty] [Parameter(ParameterSetName = LiteralPathParameterSet, Mandatory = true)] public string[] LiteralPath { get; set; } /// - /// InputObject of type System.IO.FileInfo or string with content to convert from Markdown to MarkdownInfo. + /// Gets or sets the InputObject of type System.IO.FileInfo or string with content to convert from markdown to MarkdownInfo. /// [ValidateNotNullOrEmpty] [Parameter(ParameterSetName = InputObjParamSet, Mandatory = true, ValueFromPipeline = true)] public PSObject InputObject { get; set; } /// - /// The Markdown document should be converted to a VT100 encoded string. + /// Gets or sets if the markdown document should be converted to a VT100 encoded string. /// - [Parameter()] + [Parameter] public SwitchParameter AsVT100EncodedString { get; set; } private const string PathParameterSet = "PathParamSet"; @@ -59,13 +58,13 @@ namespace Microsoft.PowerShell.Commands private MarkdownOptionInfo mdOption = null; /// - /// Override BeginProcess. + /// Override BeginProcessing. /// protected override void BeginProcessing() { - mdOption = (SessionState.PSVariable.GetValue("MarkdownOptionInfo", new MarkdownOptionInfo())) as MarkdownOptionInfo; + mdOption = SessionState.PSVariable.GetValue("MarkdownOptionInfo", new MarkdownOptionInfo()) as MarkdownOptionInfo; - if(mdOption == null) + if (mdOption == null) { throw new InvalidOperationException(); } @@ -84,18 +83,15 @@ namespace Microsoft.PowerShell.Commands switch (ParameterSetName) { case InputObjParamSet: - Object baseObj = InputObject.BaseObject; + object baseObj = InputObject.BaseObject; - //var fileInfo = baseObj as FileInfo; if (baseObj is FileInfo fileInfo) { WriteObject( MarkdownConverter.Convert( ReadContentFromFile(fileInfo.FullName).Result, conversionType, - mdOption - ) - ); + mdOption)); } else if (baseObj is string inpObj) { @@ -112,6 +108,7 @@ namespace Microsoft.PowerShell.Commands WriteError(errorRecord); } + break; case PathParameterSet: @@ -136,8 +133,7 @@ namespace Microsoft.PowerShell.Commands MarkdownConverter.Convert( ReadContentFromFile(resolvedPath).Result, conversionType, - optionInfo) - ); + optionInfo)); } } } @@ -151,7 +147,6 @@ namespace Microsoft.PowerShell.Commands string mdContent = await reader.ReadToEndAsync(); return mdContent; } - } private List ResolvePath(string path, bool isLiteral) @@ -186,10 +181,12 @@ namespace Microsoft.PowerShell.Commands if (!provider.Name.Equals("FileSystem", StringComparison.OrdinalIgnoreCase)) { string errorMessage = StringUtil.Format(ConvertMarkdownStrings.FileSystemPathsOnly, path); - ErrorRecord errorRecord = new ErrorRecord(new ArgumentException(), - "OnlyFileSystemPathsSupported", - ErrorCategory.InvalidArgument, - path); + ErrorRecord errorRecord = new ErrorRecord( + new ArgumentException(), + "OnlyFileSystemPathsSupported", + ErrorCategory.InvalidArgument, + path); + WriteError(errorRecord); return null; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MarkdownOptionCommands.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MarkdownOptionCommands.cs index e2ce0bf931..2f7cbc631b 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MarkdownOptionCommands.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MarkdownOptionCommands.cs @@ -2,22 +2,22 @@ // Licensed under the MIT License. using System; -using System.IO; -using System.Threading.Tasks; -using System.Collections.ObjectModel; using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.IO; using System.Management.Automation; +using System.Threading.Tasks; using Microsoft.PowerShell.MarkdownRender; namespace Microsoft.PowerShell.Commands { /// + /// Class for implementing Set-MarkdownOption cmdlet. /// [Cmdlet( VerbsCommon.Set, "MarkdownOption", DefaultParameterSetName = IndividualSetting, - HelpUri = "TBD" - )] + HelpUri = "TBD")] [OutputType(typeof(Microsoft.PowerShell.MarkdownRender.MarkdownOptionInfo))] public class SetMarkdownOptionCommand : PSCmdlet { @@ -26,83 +26,83 @@ namespace Microsoft.PowerShell.Commands /// [ValidatePattern(@"^\[*[0-9;]*?m{1}")] [Parameter(ParameterSetName = IndividualSetting)] - public string Header1Color { get; set;} + public string Header1Color { get; set; } /// /// Gets or sets the VT100 escape sequence for Header Level 2. /// [ValidatePattern(@"^\[*[0-9;]*?m{1}")] [Parameter(ParameterSetName = IndividualSetting)] - public string Header2Color { get; set;} + public string Header2Color { get; set; } /// /// Gets or sets the VT100 escape sequence for Header Level 3. /// [ValidatePattern(@"^\[*[0-9;]*?m{1}")] [Parameter(ParameterSetName = IndividualSetting)] - public string Header3Color { get; set;} + public string Header3Color { get; set; } /// /// Gets or sets the VT100 escape sequence for Header Level 4. /// [ValidatePattern(@"^\[*[0-9;]*?m{1}")] [Parameter(ParameterSetName = IndividualSetting)] - public string Header4Color { get; set;} + public string Header4Color { get; set; } /// /// Gets or sets the VT100 escape sequence for Header Level 5. /// [ValidatePattern(@"^\[*[0-9;]*?m{1}")] [Parameter(ParameterSetName = IndividualSetting)] - public string Header5Color { get; set;} + public string Header5Color { get; set; } /// /// Gets or sets the VT100 escape sequence for Header Level 6. /// [ValidatePattern(@"^\[*[0-9;]*?m{1}")] [Parameter(ParameterSetName = IndividualSetting)] - public string Header6Color { get; set;} + public string Header6Color { get; set; } /// /// Gets or sets the VT100 escape sequence for code block background. /// [ValidatePattern(@"^\[*[0-9;]*?m{1}")] [Parameter(ParameterSetName = IndividualSetting)] - public string Code { get; set;} + public string Code { get; set; } /// /// Gets or sets the VT100 escape sequence for image alt text foreground. /// [ValidatePattern(@"^\[*[0-9;]*?m{1}")] [Parameter(ParameterSetName = IndividualSetting)] - public string ImageAltTextForegroundColor { get; set;} + public string ImageAltTextForegroundColor { get; set; } /// /// Gets or sets the VT100 escape sequence for link foreground. /// [ValidatePattern(@"^\[*[0-9;]*?m{1}")] [Parameter(ParameterSetName = IndividualSetting)] - public string LinkForegroundColor { get; set;} + public string LinkForegroundColor { get; set; } /// /// Gets or sets the VT100 escape sequence for italics text foreground. /// [ValidatePattern(@"^\[*[0-9;]*?m{1}")] [Parameter(ParameterSetName = IndividualSetting)] - public string ItalicsForegroundColor { get; set;} + public string ItalicsForegroundColor { get; set; } /// /// Gets or sets the VT100 escape sequence for bold text foreground. /// [ValidatePattern(@"^\[*[0-9;]*?m{1}")] [Parameter(ParameterSetName = IndividualSetting)] - public string BoldForegroundColor { get; set;} + public string BoldForegroundColor { get; set; } /// /// Gets or sets the switch to PassThru the values set. /// - [Parameter()] - public SwitchParameter PassThru { get; set;} + [Parameter] + public SwitchParameter PassThru { get; set; } /// /// Gets or sets the Theme. @@ -110,14 +110,14 @@ namespace Microsoft.PowerShell.Commands [ValidateNotNullOrEmpty] [Parameter(ParameterSetName = ThemeParamSet, Mandatory = true)] [ValidateSet(DarkThemeName, LightThemeName)] - public string Theme { get; set;} + public string Theme { get; set; } /// /// Gets or sets InputObject. /// [ValidateNotNullOrEmpty] [Parameter(ParameterSetName = InputObjectParamSet, Mandatory = true, ValueFromPipeline = true)] - public PSObject InputObject { get; set;} + public PSObject InputObject { get; set; } private const string IndividualSetting = "IndividualSetting"; private const string InputObjectParamSet = "InputObject"; @@ -133,28 +133,30 @@ namespace Microsoft.PowerShell.Commands { MarkdownOptionInfo mdOptionInfo = null; - switch(ParameterSetName) + switch (ParameterSetName) { case ThemeParamSet: mdOptionInfo = new MarkdownOptionInfo(); - if(string.Equals(Theme, LightThemeName, StringComparison.OrdinalIgnoreCase)) + if (string.Equals(Theme, LightThemeName, StringComparison.OrdinalIgnoreCase)) { mdOptionInfo.SetLightTheme(); } - else if(string.Equals(Theme, DarkThemeName, StringComparison.OrdinalIgnoreCase)) + else if (string.Equals(Theme, DarkThemeName, StringComparison.OrdinalIgnoreCase)) { mdOptionInfo.SetDarkTheme(); } + break; case InputObjectParamSet: - Object baseObj = InputObject.BaseObject; + object baseObj = InputObject.BaseObject; mdOptionInfo = baseObj as MarkdownOptionInfo; - if(mdOptionInfo == null) + if (mdOptionInfo == null) { throw new ArgumentException(); } + break; case IndividualSetting: @@ -174,57 +176,57 @@ namespace Microsoft.PowerShell.Commands private void SetOptions(MarkdownOptionInfo mdOptionInfo) { - if (!String.IsNullOrEmpty(Header1Color)) + if (!string.IsNullOrEmpty(Header1Color)) { mdOptionInfo.Header1 = Header1Color; } - if (!String.IsNullOrEmpty(Header2Color)) + if (!string.IsNullOrEmpty(Header2Color)) { mdOptionInfo.Header2 = Header2Color; } - if (!String.IsNullOrEmpty(Header3Color)) + if (!string.IsNullOrEmpty(Header3Color)) { mdOptionInfo.Header3 = Header3Color; } - if (!String.IsNullOrEmpty(Header4Color)) + if (!string.IsNullOrEmpty(Header4Color)) { mdOptionInfo.Header4 = Header4Color; } - if (!String.IsNullOrEmpty(Header5Color)) + if (!string.IsNullOrEmpty(Header5Color)) { mdOptionInfo.Header5 = Header5Color; } - if (!String.IsNullOrEmpty(Header6Color)) + if (!string.IsNullOrEmpty(Header6Color)) { mdOptionInfo.Header6 = Header6Color; } - if (!String.IsNullOrEmpty(Code)) + if (!string.IsNullOrEmpty(Code)) { mdOptionInfo.Code = Code; } - if (!String.IsNullOrEmpty(ImageAltTextForegroundColor)) + if (!string.IsNullOrEmpty(ImageAltTextForegroundColor)) { mdOptionInfo.Image = ImageAltTextForegroundColor; } - if (!String.IsNullOrEmpty(LinkForegroundColor)) + if (!string.IsNullOrEmpty(LinkForegroundColor)) { mdOptionInfo.Link = LinkForegroundColor; } - if (!String.IsNullOrEmpty(ItalicsForegroundColor)) + if (!string.IsNullOrEmpty(ItalicsForegroundColor)) { mdOptionInfo.EmphasisItalics = ItalicsForegroundColor; } - if (!String.IsNullOrEmpty(BoldForegroundColor)) + if (!string.IsNullOrEmpty(BoldForegroundColor)) { mdOptionInfo.EmphasisBold = BoldForegroundColor; } @@ -236,15 +238,14 @@ namespace Microsoft.PowerShell.Commands /// [Cmdlet( VerbsCommon.Get, "MarkdownOption", - HelpUri = "TBD" - )] + HelpUri = "TBD")] [OutputType(typeof(Microsoft.PowerShell.MarkdownRender.MarkdownOptionInfo))] public class GetMarkdownOptionCommand : PSCmdlet { private const string MarkdownOptionInfoVariableName = "MarkdownOptionInfo"; /// - /// Override endproessing. + /// Override EndProcessing. /// protected override void EndProcessing() { diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowMarkdownCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowMarkdownCommand.cs index 6a6839b22f..d2d4601698 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowMarkdownCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/ShowMarkdownCommand.cs @@ -2,11 +2,11 @@ // Licensed under the MIT License. using System; -using System.IO; using System.Collections; -using System.Collections.ObjectModel; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Diagnostics; +using System.IO; using System.Management.Automation; using Microsoft.PowerShell.MarkdownRender; @@ -19,31 +19,31 @@ namespace Microsoft.PowerShell.Commands /// [Cmdlet( VerbsCommon.Show, "Markdown", - HelpUri = "TBD" - )] + HelpUri = "TBD")] [OutputType(typeof(string))] public class ShowMarkdownCommand : PSCmdlet { /// - /// InputObject of type Microsoft.PowerShell.MarkdownRender.MarkdownInfo to display + /// Gets or sets InputObject of type Microsoft.PowerShell.MarkdownRender.MarkdownInfo to display. /// [ValidateNotNullOrEmpty] [Parameter(Mandatory = true, ValueFromPipeline = true)] public PSObject InputObject { get; set; } /// - /// Switch to view Html in default browser. + /// Gets or sets the switch to view Html in default browser. /// - [Parameter()] + [Parameter] public SwitchParameter UseBrowser { get; set; } private SteppablePipeline stepPipe; /// + /// Override BeginProcessing. /// protected override void BeginProcessing() { - if(! this.MyInvocation.BoundParameters.ContainsKey("UseBrowser")) + if (!this.MyInvocation.BoundParameters.ContainsKey("UseBrowser")) { // Since UseBrowser is not bound, we use proxy to Out-Default stepPipe = ScriptBlock.Create(@"Microsoft.PowerShell.Core\Out-Default @PSBoundParameters").GetSteppablePipeline(this.MyInvocation.CommandOrigin); @@ -52,11 +52,11 @@ namespace Microsoft.PowerShell.Commands } /// - /// Override ProcessRecord + /// Override ProcessRecord. /// protected override void ProcessRecord() { - Object inpObj = InputObject.BaseObject; + object inpObj = InputObject.BaseObject; var markdownInfo = inpObj as MarkdownInfo; if (markdownInfo == null) @@ -75,15 +75,15 @@ namespace Microsoft.PowerShell.Commands { var html = markdownInfo.Html; - if (!String.IsNullOrEmpty(html)) + if (!string.IsNullOrEmpty(html)) { - string tmpFilePath = Path.Combine(Path.GetTempPath(), (Guid.NewGuid().ToString() + ".html")); + string tmpFilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".html"); using (var writer = new StreamWriter(new FileStream(tmpFilePath, FileMode.Create, FileAccess.Write, FileShare.Write))) { writer.Write(html); } - if(OutputBypassTestHook) + if (outputBypassTestHook) { WriteObject(html); return; @@ -116,15 +116,15 @@ namespace Microsoft.PowerShell.Commands { var vt100String = markdownInfo.VT100EncodedString; - if(!String.IsNullOrEmpty(vt100String)) + if (!string.IsNullOrEmpty(vt100String)) { - if(OutputBypassTestHook) + if (outputBypassTestHook) { WriteObject(vt100String); return; } - if(stepPipe != null) + if (stepPipe != null) { stepPipe.Process(vt100String); } @@ -148,21 +148,22 @@ namespace Microsoft.PowerShell.Commands /// protected override void EndProcessing() { - if(stepPipe != null) + if (stepPipe != null) { stepPipe.End(); } } - private static bool OutputBypassTestHook = false; + private static bool outputBypassTestHook = false; /// /// Test hook to enable or disable launching of browser. /// When set, the converted output is returned. /// + /// True to enable test hook, false to disable. public static void SetOutputBypassTestHook(bool value) { - OutputBypassTestHook = value; + outputBypassTestHook = value; } } } diff --git a/src/Microsoft.PowerShell.MarkdownRender/CodeInlineRenderer.cs b/src/Microsoft.PowerShell.MarkdownRender/CodeInlineRenderer.cs index 35bf5e4c7d..ff755ac790 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/CodeInlineRenderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/CodeInlineRenderer.cs @@ -4,8 +4,8 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax.Inlines; using Markdig.Renderers; +using Markdig.Syntax.Inlines; namespace Microsoft.PowerShell.MarkdownRender { @@ -16,7 +16,7 @@ namespace Microsoft.PowerShell.MarkdownRender { protected override void Write(VT100Renderer renderer, CodeInline obj) { - renderer.Write(renderer.EscapeSequences.FormatCode(obj.Content , isInline: true)); + renderer.Write(renderer.EscapeSequences.FormatCode(obj.Content, isInline : true)); } } } diff --git a/src/Microsoft.PowerShell.MarkdownRender/EmphasisInlineRenderer.cs b/src/Microsoft.PowerShell.MarkdownRender/EmphasisInlineRenderer.cs index a09b58b63a..b7e6bffba2 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/EmphasisInlineRenderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/EmphasisInlineRenderer.cs @@ -4,8 +4,8 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax.Inlines; using Markdig.Renderers; +using Markdig.Syntax.Inlines; namespace Microsoft.PowerShell.MarkdownRender { @@ -16,7 +16,7 @@ namespace Microsoft.PowerShell.MarkdownRender { protected override void Write(VT100Renderer renderer, EmphasisInline obj) { - renderer.Write(renderer.EscapeSequences.FormatEmphasis(obj.FirstChild.ToString() , isBold: obj.IsDouble ? true : false )); + renderer.Write(renderer.EscapeSequences.FormatEmphasis(obj.FirstChild.ToString(), isBold : obj.IsDouble ? true : false)); } } } diff --git a/src/Microsoft.PowerShell.MarkdownRender/FencedCodeBlockRenderer.cs b/src/Microsoft.PowerShell.MarkdownRender/FencedCodeBlockRenderer.cs index f7f4493b45..fcbdc22d6f 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/FencedCodeBlockRenderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/FencedCodeBlockRenderer.cs @@ -4,8 +4,8 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax; using Markdig.Renderers; +using Markdig.Syntax; namespace Microsoft.PowerShell.MarkdownRender { @@ -18,11 +18,11 @@ namespace Microsoft.PowerShell.MarkdownRender { foreach (var codeLine in obj.Lines.Lines) { - if (!String.IsNullOrWhiteSpace(codeLine.ToString())) + if (!string.IsNullOrWhiteSpace(codeLine.ToString())) { // If the code block is of type YAML, then tab to right to improve readability. // This specifically helps for parameters help content. - if (String.Equals(obj.Info, "yaml", StringComparison.OrdinalIgnoreCase)) + if (string.Equals(obj.Info, "yaml", StringComparison.OrdinalIgnoreCase)) { renderer.WriteLine("\t" + codeLine.ToString()); } diff --git a/src/Microsoft.PowerShell.MarkdownRender/HeaderBlockRenderer.cs b/src/Microsoft.PowerShell.MarkdownRender/HeaderBlockRenderer.cs index 29bfb76eb7..4aa78c6aea 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/HeaderBlockRenderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/HeaderBlockRenderer.cs @@ -4,8 +4,8 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax; using Markdig.Renderers; +using Markdig.Syntax; namespace Microsoft.PowerShell.MarkdownRender { @@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.MarkdownRender protected override void Write(VT100Renderer renderer, HeadingBlock obj) { // Format header and then add blank line to improve readability. - switch(obj.Level) + switch (obj.Level) { case 1: renderer.WriteLine(renderer.EscapeSequences.FormatHeader1(obj.Inline.FirstChild.ToString())); diff --git a/src/Microsoft.PowerShell.MarkdownRender/LeafInlineRenderer.cs b/src/Microsoft.PowerShell.MarkdownRender/LeafInlineRenderer.cs index ff2a202bed..e59c108998 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/LeafInlineRenderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/LeafInlineRenderer.cs @@ -4,8 +4,8 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax.Inlines; using Markdig.Renderers; +using Markdig.Syntax.Inlines; namespace Microsoft.PowerShell.MarkdownRender { @@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.MarkdownRender // If the next sibling is null, then this is the last line in the paragraph. // Add new line character at the end. // Else just write without newline at the end. - if(obj.NextSibling == null) + if (obj.NextSibling == null) { renderer.WriteLine(obj.ToString()); } diff --git a/src/Microsoft.PowerShell.MarkdownRender/LineBreakRenderer.cs b/src/Microsoft.PowerShell.MarkdownRender/LineBreakRenderer.cs index 2f5a630306..81e787d2ab 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/LineBreakRenderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/LineBreakRenderer.cs @@ -4,12 +4,11 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax.Inlines; using Markdig.Renderers; +using Markdig.Syntax.Inlines; namespace Microsoft.PowerShell.MarkdownRender { - /// /// Renderer for adding VT100 escape sequences for line breaks. /// @@ -19,7 +18,7 @@ namespace Microsoft.PowerShell.MarkdownRender { // If it is a hard line break add new line at the end. // Else, add a space for after the last character to improve readability. - if(obj.IsHard) + if (obj.IsHard) { renderer.WriteLine(); } diff --git a/src/Microsoft.PowerShell.MarkdownRender/LinkInlineRenderer.cs b/src/Microsoft.PowerShell.MarkdownRender/LinkInlineRenderer.cs index 2028b7488d..975efd519f 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/LinkInlineRenderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/LinkInlineRenderer.cs @@ -4,8 +4,8 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax.Inlines; using Markdig.Renderers; +using Markdig.Syntax.Inlines; namespace Microsoft.PowerShell.MarkdownRender { @@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.MarkdownRender protected override void Write(VT100Renderer renderer, LinkInline obj) { // Format link as image or link. - if(obj.IsImage) + if (obj.IsImage) { renderer.Write(renderer.EscapeSequences.FormatImage(obj.FirstChild.ToString())); } diff --git a/src/Microsoft.PowerShell.MarkdownRender/ListBlockRenderer.cs b/src/Microsoft.PowerShell.MarkdownRender/ListBlockRenderer.cs index 5ee5dd5da8..d1f96a274a 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/ListBlockRenderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/ListBlockRenderer.cs @@ -4,8 +4,8 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax; using Markdig.Renderers; +using Markdig.Syntax; namespace Microsoft.PowerShell.MarkdownRender { @@ -42,7 +42,7 @@ namespace Microsoft.PowerShell.MarkdownRender // For a numbered list, we need to make sure the index is incremented. foreach (var line in block) { - if(line is ParagraphBlock paragraphBlock) + if (line is ParagraphBlock paragraphBlock) { renderer.Write(index.ToString()).Write(". ").Write(paragraphBlock.Inline); } diff --git a/src/Microsoft.PowerShell.MarkdownRender/ListItemBlockRenderer.cs b/src/Microsoft.PowerShell.MarkdownRender/ListItemBlockRenderer.cs index d96b744d65..eaea89b5b3 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/ListItemBlockRenderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/ListItemBlockRenderer.cs @@ -5,8 +5,8 @@ using System; using System.IO; using System.Threading; using Markdig; -using Markdig.Syntax; using Markdig.Renderers; +using Markdig.Syntax; namespace Microsoft.PowerShell.MarkdownRender { @@ -38,20 +38,21 @@ namespace Microsoft.PowerShell.MarkdownRender var paragraphBlock = block as ParagraphBlock; - if(paragraphBlock != null) + if (paragraphBlock != null) { renderer.Write(indent).Write(listBullet).Write(" ").Write(paragraphBlock.Inline); } - else //If there is a sublist, the block is a ListBlock instead of ParagraphBlock. + else { + // If there is a sublist, the block is a ListBlock instead of ParagraphBlock. var subList = block as ListBlock; if (subList != null) { - foreach(var subListItem in subList) + foreach (var subListItem in subList) { var subListItemBlock = subListItem as ListItemBlock; - if(subListItemBlock != null) + if (subListItemBlock != null) { foreach (var line in subListItemBlock) { @@ -67,16 +68,19 @@ namespace Microsoft.PowerShell.MarkdownRender // Typical padding is at most a screen's width, any more than that and we won't bother caching. private const int IndentCacheMax = 120; private static readonly string[] IndentCache = new string[IndentCacheMax]; + internal static string Padding(int countOfSpaces) { if (countOfSpaces >= IndentCacheMax) + { return new string(' ', countOfSpaces); + } var result = IndentCache[countOfSpaces]; if (result == null) { - Interlocked.CompareExchange(ref IndentCache[countOfSpaces], new string(' ', countOfSpaces), comparand:null); + Interlocked.CompareExchange(ref IndentCache[countOfSpaces], new string(' ', countOfSpaces), comparand : null); result = IndentCache[countOfSpaces]; } diff --git a/src/Microsoft.PowerShell.MarkdownRender/MarkdownConverter.cs b/src/Microsoft.PowerShell.MarkdownRender/MarkdownConverter.cs index 0ab0bf5412..a1041e7978 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/MarkdownConverter.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/MarkdownConverter.cs @@ -4,8 +4,8 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax; using Markdig.Renderers; +using Markdig.Syntax; namespace Microsoft.PowerShell.MarkdownRender { @@ -32,17 +32,17 @@ namespace Microsoft.PowerShell.MarkdownRender public class MarkdownInfo { /// - /// Html content after conversion. + /// Gets the Html content after conversion. /// - public string Html { get; internal set;} + public string Html { get; internal set; } /// - /// VT100 encoded string after conversion. + /// Gets the VT100 encoded string after conversion. /// - public string VT100EncodedString { get; internal set;} + public string VT100EncodedString { get; internal set; } /// - /// AST of the markdown string. + /// Gets the AST of the markdown string. /// public Markdig.Syntax.MarkdownDocument Tokens { get; internal set; } } @@ -55,25 +55,27 @@ namespace Microsoft.PowerShell.MarkdownRender /// /// Convert from markdown string to VT100 encoded string or HTML. Returns MarkdownInfo object. /// - /// string with markdown content to be converted - /// specifies type of conversion, either VT100 or HTML - /// specifies the rendering options for VT100 rendering + /// String with markdown content to be converted. + /// Specifies type of conversion, either VT100 or HTML. + /// Specifies the rendering options for VT100 rendering. + /// MarkdownInfo object with the converted output. public static MarkdownInfo Convert(string markdownString, MarkdownConversionType conversionType, MarkdownOptionInfo optionInfo) { var renderInfo = new MarkdownInfo(); var writer = new StringWriter(); MarkdownPipeline pipeline = null; - if(conversionType.HasFlag(MarkdownConversionType.HTML)) + if (conversionType.HasFlag(MarkdownConversionType.HTML)) { pipeline = new MarkdownPipelineBuilder().UseAdvancedExtensions().Build(); var renderer = new Markdig.Renderers.HtmlRenderer(writer); renderInfo.Html = Markdig.Markdown.Convert(markdownString, renderer, pipeline).ToString(); } - if(conversionType.HasFlag(MarkdownConversionType.VT100)) + if (conversionType.HasFlag(MarkdownConversionType.VT100)) { pipeline = new MarkdownPipelineBuilder().Build(); + // Use the VT100 renderer. var renderer = new VT100Renderer(writer, optionInfo); renderInfo.VT100EncodedString = Markdig.Markdown.Convert(markdownString, renderer, pipeline).ToString(); diff --git a/src/Microsoft.PowerShell.MarkdownRender/ParagraphBlockRenderer.cs b/src/Microsoft.PowerShell.MarkdownRender/ParagraphBlockRenderer.cs index fa7043d07f..2e7eec16cb 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/ParagraphBlockRenderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/ParagraphBlockRenderer.cs @@ -4,8 +4,8 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax; using Markdig.Renderers; +using Markdig.Syntax; namespace Microsoft.PowerShell.MarkdownRender { @@ -18,6 +18,7 @@ namespace Microsoft.PowerShell.MarkdownRender { // Call the renderer for children, leaf inline or line breaks. renderer.WriteChildren(obj.Inline); + // Add new line at the end of the paragraph. renderer.WriteLine(); } diff --git a/src/Microsoft.PowerShell.MarkdownRender/QuoteBlockRenderer.cs b/src/Microsoft.PowerShell.MarkdownRender/QuoteBlockRenderer.cs index a7e9217a72..f22f2ae8a4 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/QuoteBlockRenderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/QuoteBlockRenderer.cs @@ -4,8 +4,8 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax; using Markdig.Renderers; +using Markdig.Syntax; namespace Microsoft.PowerShell.MarkdownRender { @@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.MarkdownRender protected override void Write(VT100Renderer renderer, QuoteBlock obj) { // Iterate through each item and add the quote character before the content. - foreach(var item in obj) + foreach (var item in obj) { renderer.Write(obj.QuoteChar).Write(" ").Write(item); } diff --git a/src/Microsoft.PowerShell.MarkdownRender/VT100EscapeSequences.cs b/src/Microsoft.PowerShell.MarkdownRender/VT100EscapeSequences.cs index 360221bed3..32e9731af3 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/VT100EscapeSequences.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/VT100EscapeSequences.cs @@ -4,8 +4,8 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax; using Markdig.Renderers; +using Markdig.Syntax; namespace Microsoft.PowerShell.MarkdownRender { @@ -14,60 +14,60 @@ namespace Microsoft.PowerShell.MarkdownRender /// public sealed class MarkdownOptionInfo { - private const char Esc = (char) 0x1b; + private const char Esc = (char)0x1b; /// - /// Current VT100 escape sequence for header 1. + /// Gets or sets current VT100 escape sequence for header 1. /// public string Header1 { get; set; } /// - /// Current VT100 escape sequence for header 2. + /// Gets or sets current VT100 escape sequence for header 2. /// public string Header2 { get; set; } /// - /// Current VT100 escape sequence for header 3. + /// Gets or sets current VT100 escape sequence for header 3. /// public string Header3 { get; set; } /// - /// Current VT100 escape sequence for header 4. + /// Gets or sets current VT100 escape sequence for header 4. /// public string Header4 { get; set; } /// - /// Current VT100 escape sequence for header 5. + /// Gets or sets current VT100 escape sequence for header 5. /// public string Header5 { get; set; } /// - /// Current VT100 escape sequence for header 6. + /// Gets or sets current VT100 escape sequence for header 6. /// public string Header6 { get; set; } /// - /// Current VT100 escape sequence for code inline and code blocks. + /// Gets or sets current VT100 escape sequence for code inline and code blocks. /// public string Code { get; set; } /// - /// Current VT100 escape sequence for links. + /// Gets or sets current VT100 escape sequence for links. /// public string Link { get; set; } /// - /// Current VT100 escape sequence for images. + /// Gets or sets current VT100 escape sequence for images. /// public string Image { get; set; } /// - /// Current VT100 escape sequence for bold text. + /// Gets or sets current VT100 escape sequence for bold text. /// public string EmphasisBold { get; set; } /// - /// Current VT100 escape sequence for italics text. + /// Gets or sets current VT100 escape sequence for italics text. /// public string EmphasisItalics { get; set; } @@ -75,11 +75,13 @@ namespace Microsoft.PowerShell.MarkdownRender /// Get the property as an rendered escape sequence. /// This is used for typesps1xml for displaying. /// + /// Name of the property to get as escape sequence. + /// Specified property name as escape sequence. public string AsEscapeSequence(string propertyName) { var propertyValue = this.GetType().GetProperty(propertyName)?.GetValue(this) as string; - if(!String.IsNullOrEmpty(propertyValue)) + if (!string.IsNullOrEmpty(propertyValue)) { return string.Concat(Esc, propertyValue, propertyValue, Esc, "[0m"); } @@ -90,7 +92,7 @@ namespace Microsoft.PowerShell.MarkdownRender } /// - /// Set dark as the default theme. + /// Initializes a new instance of class and sets dark as the default theme. /// public MarkdownOptionInfo() { @@ -134,23 +136,24 @@ namespace Microsoft.PowerShell.MarkdownRender } } - /// - /// Class to represent default VT100 escape sequences - /// + /// + /// Class to represent default VT100 escape sequences. + /// public class VT100EscapeSequences { - private const char Esc = (char) 0x1B; + private const char Esc = (char)0x1B; - private string EndSequence = Esc + "[0m"; + private string endSequence = Esc + "[0m"; private MarkdownOptionInfo options; /// - /// Set the options as per + /// Initializes a new instance of the class. /// + /// MarkdownOptionInfo object to initialize with. public VT100EscapeSequences(MarkdownOptionInfo optionInfo) { - if(optionInfo == null) + if (optionInfo == null) { throw new ArgumentNullException("optionInfo"); } @@ -158,100 +161,124 @@ namespace Microsoft.PowerShell.MarkdownRender options = optionInfo; } - /// - /// Class to represent default VT100 escape sequences - /// + /// + /// Class to represent default VT100 escape sequences. + /// + /// Text of the header to format. + /// Formatted Header 1 string. public string FormatHeader1(string headerText) { - return String.Concat(Esc, options.Header1, headerText, EndSequence); + return string.Concat(Esc, options.Header1, headerText, endSequence); } - /// - /// Class to represent default VT100 escape sequences - /// + /// + /// Class to represent default VT100 escape sequences. + /// + /// Text of the header to format. + /// Formatted Header 2 string. public string FormatHeader2(string headerText) { - return String.Concat(Esc, options.Header2, headerText, EndSequence); + return string.Concat(Esc, options.Header2, headerText, endSequence); } - /// - /// Class to represent default VT100 escape sequences - /// + /// + /// Class to represent default VT100 escape sequences. + /// + /// Text of the header to format. + /// Formatted Header 3 string. public string FormatHeader3(string headerText) { - return String.Concat(Esc, options.Header3, headerText, EndSequence); + return string.Concat(Esc, options.Header3, headerText, endSequence); } - /// - /// Class to represent default VT100 escape sequences - /// + /// + /// Class to represent default VT100 escape sequences. + /// + /// Text of the header to format. + /// Formatted Header 4 string. public string FormatHeader4(string headerText) { - return String.Concat(Esc, options.Header4, headerText, EndSequence); + return string.Concat(Esc, options.Header4, headerText, endSequence); } - /// - /// Class to represent default VT100 escape sequences - /// + /// + /// Class to represent default VT100 escape sequences. + /// + /// Text of the header to format. + /// Formatted Header 5 string. public string FormatHeader5(string headerText) { - return String.Concat(Esc, options.Header5, headerText, EndSequence); + return string.Concat(Esc, options.Header5, headerText, endSequence); } - /// - /// Class to represent default VT100 escape sequences - /// + /// + /// Class to represent default VT100 escape sequences. + /// + /// Text of the header to format. + /// Formatted Header 6 string. public string FormatHeader6(string headerText) { - return String.Concat(Esc, options.Header6, headerText, EndSequence); + return string.Concat(Esc, options.Header6, headerText, endSequence); } - /// - /// Class to represent default VT100 escape sequences - /// + /// + /// Class to represent default VT100 escape sequences. + /// + /// Text of the code block to format. + /// True if it is a inline code block, false otherwise. + /// Formatted code block string. public string FormatCode(string codeText, bool isInline) { - if(isInline) + if (isInline) { - return String.Concat(Esc, options.Code, codeText, EndSequence); + return string.Concat(Esc, options.Code, codeText, endSequence); } else { // For code blocks, [500@ make sure that the whole line has background color. - return String.Concat(Esc, options.Code, codeText, Esc, "[500@", EndSequence); + return string.Concat(Esc, options.Code, codeText, Esc, "[500@", endSequence); } } - /// - /// Class to represent default VT100 escape sequences - /// + /// + /// Class to represent default VT100 escape sequences. + /// + /// Text of the link to format. + /// URL of the link. + /// True url should be hidden, false otherwise. Default is true. + /// Formatted link string. public string FormatLink(string linkText, string url, bool hideUrl = true) { - if(hideUrl) + if (hideUrl) { - return String.Concat(Esc, options.Link, "\"", linkText, "\"", EndSequence); + return string.Concat(Esc, options.Link, "\"", linkText, "\"", endSequence); } else { - return String.Concat("\"", linkText, "\" (", Esc, options.Link, url, EndSequence, ")"); + return string.Concat("\"", linkText, "\" (", Esc, options.Link, url, endSequence, ")"); } } - /// - /// Class to represent default VT100 escape sequences - /// + /// + /// Class to represent default VT100 escape sequences. + /// + /// Text to format as emphasis. + /// True if it is to be formatted as bold, false to format it as italics. + /// Formatted emphasis string. public string FormatEmphasis(string emphasisText, bool isBold) { var sequence = isBold ? options.EmphasisBold : options.EmphasisItalics; - return String.Concat(Esc, sequence, emphasisText, EndSequence); + return string.Concat(Esc, sequence, emphasisText, endSequence); } - /// - /// Class to represent default VT100 escape sequences - /// + /// + /// Class to represent default VT100 escape sequences. + /// + /// Text of the image to format. + /// Formatted image string. public string FormatImage(string altText) { - return String.Concat(Esc, options.Image, "[", altText, "]", EndSequence); + return string.Concat(Esc, options.Image, "[", altText, "]", endSequence); } } } diff --git a/src/Microsoft.PowerShell.MarkdownRender/VT100ObjectRenderer.cs b/src/Microsoft.PowerShell.MarkdownRender/VT100ObjectRenderer.cs index 1cfd1bb04a..47373a50e1 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/VT100ObjectRenderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/VT100ObjectRenderer.cs @@ -4,14 +4,15 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax; using Markdig.Renderers; +using Markdig.Syntax; namespace Microsoft.PowerShell.MarkdownRender { /// /// Implement the MarkdownObjectRenderer with VT100Renderer. /// + /// The element type of the renderer. public abstract class VT100ObjectRenderer : MarkdownObjectRenderer where T : MarkdownObject { } diff --git a/src/Microsoft.PowerShell.MarkdownRender/VT100Renderer.cs b/src/Microsoft.PowerShell.MarkdownRender/VT100Renderer.cs index ff085b06f8..59b8234d9c 100644 --- a/src/Microsoft.PowerShell.MarkdownRender/VT100Renderer.cs +++ b/src/Microsoft.PowerShell.MarkdownRender/VT100Renderer.cs @@ -4,19 +4,21 @@ using System; using System.IO; using Markdig; -using Markdig.Syntax; using Markdig.Renderers; +using Markdig.Syntax; namespace Microsoft.PowerShell.MarkdownRender { /// - /// Implementation of the VT100 renderer. + /// Initializes an instance of the VT100 renderer. /// public sealed class VT100Renderer : TextRendererBase { /// - /// Initialize the VT100 renderer with and write the output . + /// Initializes a new instance of the class. /// + /// TextWriter to write to. + /// MarkdownOptionInfo object with options. public VT100Renderer(TextWriter writer, MarkdownOptionInfo optionInfo) : base(writer) { EscapeSequences = new VT100EscapeSequences(optionInfo); @@ -36,8 +38,8 @@ namespace Microsoft.PowerShell.MarkdownRender } /// - /// Get the current escape sequences. + /// Gets the current escape sequences. /// - public VT100EscapeSequences EscapeSequences { get; private set;} + public VT100EscapeSequences EscapeSequences { get; private set; } } }