Unexpected formatting in triple-tick code blocks

AI-generated summary

The discussion, Unexpected formatting in triple-tick code blocks, revolves around improper formatting in triple-backtick code blocks. ganncamp noticed that some formatting is applied in these blocks, sharing a screenshot to demonstrate. per1234 inquired about the “Default code lang” site setting, which ganncamp revealed to be set to auto. supermathie explained that the auto language detection is causing the issue, as it incorrectly detects the language as markdown. To resolve this, supermathie suggested changing the default code language to text or specifying the language for each code block, such as using text to prevent formatting. renato added that this is due to syntax highlighting with the wrong language after HighlightJS auto-detection, which does not occur on Meta because the “Default code lang” is set to text. ganncamp questioned why formatting would ever be applied in a code block.

I know a new editor is in the works, but presumably the underlying markdown will be the same, and its interpolation will stay the same, so…

In triple-backtick (```) code blocks, I’ve noticed that some formatting is improperly applied. Here’s a screenshot from me fixing a user’s post. This is the before:

If I change it to a single-tick block there’s no formatting, as expected (please ignore the Grammarly underline on the left):

Hi @ganncamp. What is the value of the “Default code lang” site setting on that forum?

It’s auto

The auto lang for this particular code block is detecting the language as markdown, that’s why:

(lang=auto; my incomplete snippet is detected as ruby)

sonar-scanner … etc etc include=src/**,apps/**,include/**,gui/** -Dsonar=true…

(lang=markdown)

sonar-scanner … etc etc include=src/**,apps/**,include/**,gui/** -Dsonar=true…

(lang=text)

sonar-scanner … etc etc include=src/**,apps/**,include/**,gui/** -Dsonar=true…

(lang=bash)

sonar-scanner … etc etc include=src/**,apps/**,include/**,gui/** -Dsonar=true…

You can change this for every post by changing the default code lang to text or one post by writing e.g.:

```text
sonar-scanner … etc etc include=src/**,apps/**,include/**,gui/** -Dsonar=true…
```

producing the (lang=text) block above

But why would formatting ever be applied in a code block?

It’s just syntax highlighting your code, but with the wrong language after HighlightJS “auto-detected” it.

Notice the same doesn’t happen here on Meta unless you explicitly start your code block with ```auto, because we have “Default code lang” set as text.