Skip to main content
2 of 9
added 76 characters in body
Pxtl
  • 956
  • 4
  • 4

feature-request: proper syntax highlighting for Powershell

Tagging a scriptblock with powershell

(ignore the backslashes)

\```powershell
Write-Output "Hello, $Env:USERNAME"
\```

produces no syntax highlighting.

Write-Output "Hello, $Env:USERNAME"

Powershell snippet with no highlighting

This behavior holds for other common aliases for Powershell - ```ps, ```ps1, etc.

You can trick it into the default highlighter by using ```lang-powershell

powershell snippet with crude highlighting

which is better than nothing, but it is obviously triggering the fallback default highlighter. Note that the environment variable within the interpolated string is not properly highlighted as a variable. Compare vs the standard syntax highlighter built into windows:

enter image description here

So there are really two requests here:

  1. At least offer the default syntax highlighter on the ```powershell and ```ps names. For example, the block below uses the ```cs name, not the verbose ```lang-cs. I didn't even know about the need for the "lang-" prefix until I started researching this feature-request, since I'd always been able to discover the short-form of the ```shortcode by guessing! The "lang-" prefix is non-discoverable and you have to go to documentation to learn about it, I've never seen it in any other Markdown implementation of fenced-code-blocks. It's not even mentioned in the formatting-help sidebar.
Console.WriteLine($"Hello, {Environment.UserName}.");
  1. Ideally, a proper syntax highlighter for Powershell that understands the language fully, including its string-interpolation syntax. Note how the cs snippet above gets proper $"string interpolation"
Pxtl
  • 956
  • 4
  • 4