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