7

Syntax highlighting for both Powershell and Batch works if specified manually in an HTML comment, but not via a code block:

  • Doesn't Work: (code block)
    • ```bat
      
    • ```powershell
      

  • Works: (HTML comment)
    • <!-- language-all: lang-bat -->
      <!-- language: lang-bat -->
    • <!-- language-all: lang-powershell -->
      <!-- language: lang-powershell -->

Why is there this disparity?

  • I'm not familiar with how StackExchange sites individually function, but wouldn't it be a lot simpler and efficient, causing less discombobulation, if shell languages were supported the same across all sites supporting code block markdown?

    For example, syntax highlighting for both Powershell and Batch are auto-applied on StackOverflow.
6
  • 1
    SE no longer uses Google Code Prettify, is has switched to CommonMark. Stack Overflow is migrating to CommonMark on Saturday, June 20, 2020 - Meta Stack Overflow
    – DavidPostill Mod
    Commented Jul 1, 2020 at 12:26
  • @DavidPostill Thanks! I wasn't aware of that. Do you have any insight into the disparity between syntax specified via code block vs HTML comment?
    – JW0914
    Commented Jul 1, 2020 at 12:28
  • 1
    We're switching to CommonMark - Meta Stack Exchange shows a space after the code fence. Have you tried that?
    – DavidPostill Mod
    Commented Jul 1, 2020 at 12:32
  • Having said that it may be a bug as the CommonMark spec shows examples with no spaces after the code fance.
    – DavidPostill Mod
    Commented Jul 1, 2020 at 12:39
  • @DavidPostill I just tried with and without a space following the code fence and neither works on Superuser (screenshots of all four - with and without space after code fence and with and without -all in HTML comment)
    – JW0914
    Commented Jul 1, 2020 at 12:48
  • 1
    Fixed. See my answer. And thanks for spotting the issue!
    – DavidPostill Mod
    Commented Jul 1, 2020 at 13:16

1 Answer 1

6

Why is there a disparity between code fences and HTML comments used to set language?

Reproduced and fixed.

The issue was that the "Code Language (used for syntax highlighting)" in the tag descriptions was set to "none".

Changing that to "default" in and fixed the issue:

enter image description here

Note that the list of languages available do not include options that are more suited to or so I took a guess and used "default".

Here is my test question (which I'm going to delete)

Source:

testing common mark for batch files and powershell

```batch
echo Hello World!
```

```powershell
Write-Host "Hello World"
```

<!-- language: lang-bat -->
    echo Hello World!


<!-- language: lang-powershell -->
    Write-Host "Hello World"

Rendered:

enter image description here

3
  • Just an FYI, the issue is occurring again... it worked for a while, but if specifying powershell or bat after a code fence, it's not applying any syntax highlighting in the preview or when saved. Could this be browser-specific, occurring in one browser but not another (I use Chromium-based Edge)?
    – JW0914
    Commented Sep 17, 2020 at 12:25
  • 1
    No idea, but I would not do anything until the new syntax highlighter is rolled out network wide (Sep 24th?). See meta.stackexchange.com/questions/353983/…
    – DavidPostill Mod
    Commented Sep 17, 2020 at 12:29
  • 1
    Highlight for the cmd/bat language codes in source fences seems to not be working currently.
    – bad_coder
    Commented Oct 18, 2021 at 15:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .