Skip to content

Conversation

@adityapatwardhan
Copy link
Member

Fix #7283

PR Summary

  • Formatting changes moved from types file to formatting file.
  • Add logic to check VT100 support before adding VT100 escape sequences.
  • Add online help uris.
  • Add positional parameters for Convert-FromMarkdown and Set-MarkdownOption

PR Checklist

…meter issues for Markdown cmdlets

* Formatting changes moved from types file to formatting file.
* Add logic to check VT100 support before adding VT100 escape sequences.
* Add online help uris.
* Add positional parameters for Convert-FromMarkdown and Set-MarkdownOption
public string FormatHeader2(string headerText)
{
return string.Concat(Esc, options.Header2, headerText, endSequence);
if (options.EnableVT100Encoding)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of similar code, perhaps have a helper that does the EnableVT100Encoding check and concats or just returns the string?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed for header types. For others the code is slightly different for each so kept it as is.

@iSazonov
Copy link
Collaborator

Usually we use

[Alias("PSPath", "LP")]

for LiteralPath parameters.

Copy link
Collaborator

@iSazonov iSazonov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave a comment

/// </summary>
protected override void BeginProcessing()
{
mdOption = SessionState.PSVariable.GetValue("MarkdownOptionInfo", new MarkdownOptionInfo()) as MarkdownOptionInfo;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about "MarkdownOptionInfo" -> "PSMarkdownOptionInfo"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer MarkdownOptionInfo since the cmdlet is Get-MarkdownOption. @daxian-dbw your thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for any variables that are part of PowerShell itself, it should have the PS prefix to avoid name collision. So this should be PSMarkdownOptionInfo. cc @joeyaiello

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable MarkdownOptionInfo should be saved in the module scope of the Utility module, instead of the current scope of the current session state. Doing the latter will make the persistence of markdown option unreliable/inconsistent.

And, did you consider other options to persist the markdown option? I don't have an alternative off the top of my mind, but would like to check if you considered anything else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SteveL-MSFT if we agree it should be moved to the module state, does it matter?

As for persistence, I think it's okay to tell people to put this stuff in their profile until we hear why that's not good enough (seems to work just fine for PSReadline).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daxian-dbw The committee feedback was to have it in session state so it is valid throughout the session. The preferences can be set in profile for persistence.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm OK to have it in session state, but it should be the module session state of Microsoft.PowerShell.Utility instead of the currently active session state, which could be the global session state or another module's session state. And the scope to save the variable should be the module scope, not the current scope.

For example, if I'm running Set-MarkdownOptions in a function from another module, then the variable will be saved in the function scope under the session state of that module, which will be lost once the function finishes execution.

@rkeithhill
Copy link
Collaborator

👍 for positional parameter support. When ConvertFrom-Markdown .\README.md generated an error, I was bummed.

@adityapatwardhan
Copy link
Member Author

@SteveL-MSFT please have another look.

{
mdOption = SessionState.PSVariable.GetValue("MarkdownOptionInfo", new MarkdownOptionInfo()) as MarkdownOptionInfo;

if (!this.Host.UI.SupportsVirtualTerminal)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.Host can be null if the cmdlet is invoked in a runspace without a PSHost.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

/// </summary>
protected override void BeginProcessing()
{
mdOption = SessionState.PSVariable.GetValue("MarkdownOptionInfo", new MarkdownOptionInfo()) as MarkdownOptionInfo;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for any variables that are part of PowerShell itself, it should have the PS prefix to avoid name collision. So this should be PSMarkdownOptionInfo. cc @joeyaiello

@SteveL-MSFT
Copy link
Member

On macOS using the Terminal app, it doesn't seem to display the VT100 inverted sequence so the text becomes unreadable since the color is supposed to be black on inverted background but just appears as black. A basic web search doesn't find anything on how to support this so we may need to special case macOS to use some other colors.

@SteveL-MSFT
Copy link
Member

I take back part of what I said. Inverse works for Headers like

# header

But this only renders as black text on black background

`text`

@adityapatwardhan
Copy link
Member Author

@PaulHigin @SteveL-MSFT @daxian-dbw Please have another look.

protected override void BeginProcessing()
{
mdOption = SessionState.PSVariable.GetValue("MarkdownOptionInfo", new MarkdownOptionInfo()) as MarkdownOptionInfo;
mdOption = SessionState.PSVariable.GetValue("PSMarkdownOptionInfo", new PSMarkdownOptionInfo()) as PSMarkdownOptionInfo;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as in #7329 (comment)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@daxian-dbw daxian-dbw added the WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module label Jul 25, 2018
private const string Header6Dark = "[4;97m";
private const string CodeDark = "[48;2;155;155;155;38;2;30;30;30m";

private const string CodeMacOS = "[107;95m";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should add a comment why we are special casing macOS

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment.

throw new InvalidOperationException();
}

if (this.Host != null && this.Host.UI.SupportsVirtualTerminal)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.Host.UI.SupportsVirtualTerminal is not needed twice here. But it seems like the logic should be:

mdOption.EnableVT100Encoding = mdOption.EnableVT100Encoding && (this.Host != null) && (this.Host.UI.SupportsVirtualTerminal);

If there is no host I assume EnableVT100Encoding option should be disabled?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PaulHigin improved it a bit by using nullable bool.

@adityapatwardhan
Copy link
Member Author

@PaulHigin @SteveL-MSFT @daxian-dbw Please have a look.


// supportsVT100 == null if the host is null.
// supportsVT100 == false if host does not support VT100.
if (supportsVT100 == null || supportsVT100 == false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. I think you can just do if (supportsVT100 != true) here.

Copy link
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SteveL-MSFT
Copy link
Member

@adityapatwardhan can you review the CodeFactor issues?

@adityapatwardhan
Copy link
Member Author

@SteveL-MSFT I have fixed a few CodeFactor issues. Others are either following a pattern which already exists or a rule we want to disable.

@daxian-dbw Can you have another look?

Copy link
Member

@daxian-dbw daxian-dbw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more comment. Otherwise look good to me.

It "Verify PSMarkdownOptionInfo is defined in module scope" {

$mod = Get-Module Microsoft.PowerShell.Utility
$options = & $mod { $PSMarkdownOptionInfo }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better add one check for $PSMarkdownOptionInfo -eq $null before this line, to make sure that the variable is not leaked into the global scope or current scope.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@iSazonov
Copy link
Collaborator

@daxian-dbw Is your #7329 (comment) closed?

@adityapatwardhan
Copy link
Member Author

@daxian-dbw Ready to merge?

@daxian-dbw
Copy link
Member

@iSazonov Yes, it has been changed to use the module scope to save the variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WG-Cmdlets-Utility cmdlets in the Microsoft.PowerShell.Utility module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown rendering issues with formatting and down level support

8 participants