Tagging a fenced code block with powershell
:
```powershell
Write-Output "Hello, $Env:USERNAME"
```
produces no syntax highlighting:
Write-Output "Hello, $Env:USERNAME"
This behavior holds for other common aliases for PowerShell - ps
, ps1
, etc.
You can trick it into the default highlighter by using lang-powershell
or the sh highlighter using sh
(as is mentioned in other questions ):
which is better than nothing, but is imperfect; note now the environment variable within the interpolated string is not properly highlighted as a variable. Compare vs. the standard syntax highlighter built into Windows:
So there are really two requests here:
At least offer the default syntax highlighter on the
powershell
andps
names. For example, the block below uses thecs
name, not the verboselang-cs
. I didn't even know about the need for thelang-
prefix until I started researching this feature request, since I'd always been able to discover the short-form by guessing! Thelang-
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. Usinglang-default
orsh
are non-discoverable workarounds that shouldn't be necessary.Console.WriteLine($"Hello, {Environment.UserName}.");
Ideally, a proper syntax highlighter for PowerShell that understands the language fully, including its string-interpolation syntax. Note how the C# snippet above gets proper
$"string interpolation"
Related questions:
-
This question is very informative about root-cause, but primarily focuses on the Stack Exchange tagging behavior and not fenced code blocks. Under that mechanism, using a
powershell
tag (but not apowershell-core
tag) on the post does cause thelang-default
, which is related to my request (1). However, as shown above that does not work for fenced code blocks. This is important since PowerShell is often involved answer to various Windows admin tasks on Super User and Server Fault that may not be tagged withpowershell
. Enable automatic and on-demand syntax highlighting for PowerShell (updated for highlight.js)
Functionally the same as above but includes more technical background. In particularly useful as it explains why the SE team is hesitant to add more languages (they have a performance load). This is used to explain why syntax highlighting for Julia was deferred.
However, PowerShell is an order-of-magnitude more questioned than Julia, and even now measures beyond Bash:
```powershell
on a code block, you're telling the highlighter to look at the [powershell] tag's defined highlighter for it to use; that's why tags are related here. In order to fix```powershell
, we have to fix the associated tag's selected highlighter.