Fix formatting, vt100 support, help uri and positional parameter issues for Markdown cmdlets#7329
Conversation
…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
There was a problem hiding this comment.
There's a lot of similar code, perhaps have a helper that does the EnableVT100Encoding check and concats or just returns the string?
There was a problem hiding this comment.
Fixed for header types. For others the code is slightly different for each so kept it as is.
|
Usually we use [Alias("PSPath", "LP")]for LiteralPath parameters. |
There was a problem hiding this comment.
What do you think about "MarkdownOptionInfo" -> "PSMarkdownOptionInfo"?
There was a problem hiding this comment.
I prefer MarkdownOptionInfo since the cmdlet is Get-MarkdownOption. @daxian-dbw your thoughts?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@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).
There was a problem hiding this comment.
@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.
There was a problem hiding this comment.
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.
|
👍 for positional parameter support. When |
|
@SteveL-MSFT please have another look. |
There was a problem hiding this comment.
this.Host can be null if the cmdlet is invoked in a runspace without a PSHost.
There was a problem hiding this comment.
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
|
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. |
|
I take back part of what I said. Inverse works for Headers like # headerBut this only renders as black text on black background `text` |
|
@PaulHigin @SteveL-MSFT @daxian-dbw Please have another look. |
| 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"; |
There was a problem hiding this comment.
Should add a comment why we are special casing macOS
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
@PaulHigin improved it a bit by using nullable bool.
|
@PaulHigin @SteveL-MSFT @daxian-dbw Please have a look. |
There was a problem hiding this comment.
Nit. I think you can just do if (supportsVT100 != true) here.
|
@adityapatwardhan can you review the CodeFactor issues? |
|
@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? |
daxian-dbw
left a comment
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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.
|
@daxian-dbw Is your #7329 (comment) closed? |
|
@daxian-dbw Ready to merge? |
|
@iSazonov Yes, it has been changed to use the module scope to save the variable. |
Fix #7283
PR Summary
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests