6

Tagging a fenced code block with powershell:

```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 or the sh highlighter using sh (as is mentioned in other questions ):

powershell snippet with crude highlighting

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:

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 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. Using lang-default or sh are non-discoverable workarounds that shouldn't be necessary.

    Console.WriteLine($"Hello, {Environment.UserName}.");
    
  2. 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:

6
  • Sorry, this is meant to be a feature-request for SO, not a request for tips on how to do Powershell syntax highlighting. Yes, the "sh" hack works, but it's not an ideal workflow.
    – Pxtl
    Commented Aug 9, 2023 at 16:39
  • 1
    @πάνταῥεῖ, correct me if I'm wrong, but this feature request is rather loosely related to question in linked post.
    – markalex
    Commented Aug 9, 2023 at 16:40
  • Point 1 can be done by a mod if they see fit. Point 2 is not something SE will solve unless the Highlight.js already has the implementation and isn't a resource hog when integrated by SE.
    – rene
    Commented Aug 9, 2023 at 17:07
  • 1
    See also: meta.stackoverflow.com/questions/421016/…
    – rene
    Commented Aug 9, 2023 at 17:10
  • You'll see that I've already referenced that in the related questions section, and that's about tags, when I'm talking about fenced code blocks.
    – Pxtl
    Commented Aug 9, 2023 at 18:00
  • @Pxtl I can't tell whether you've realized this, but one of the things that post references is that when you use ```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.
    – zcoop98
    Commented Aug 9, 2023 at 22:25

0

Browse other questions tagged .