3

COMMAND and OUTPUT is formatted as italics in this post. I know <pre><code> can be used to format text in code blocks, but that answer uses just a normal code fence ``` ```. Here's the rendered output on my PC

Formatted code block

But, if I copy that to somewhere else, then the code will just be plain code like expected

[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
YOUR_COMMAND_HERE | Tee-Object -FilePath YOUR_OUTPUT_FILE -Encoding UTF8NoBOM

In fact I've never seen such italic formatting in the middle in any C macros or identifiers. Here's an example

// YOUR_COMMAND_HERE
// YOUR_COMMAND_HERE | Tee-Object -FilePath YOUR_OUTPUT_FILE -Encoding UTF8NoBOM
#if SOME_NONITALIC_MACRO
int_least32_t v = INT_FAST8_MIN + INT_FAST16_MIN - INT_LEAST32_MAX;
#endif    

What's even weirder is that normally _italic_ only works if the underscore pair is surrounded by spaces and never works in the middle of a word: _this is italic_ this is italic but this_is_not this_is_not

Why does that happen?

2

2 Answers 2

5

From the page source:

<code data-highlighted="yes" class="hljs language-markdown">

In other words, the auto code highlighter has interpreted [token]: as a reference link, and _token_ as italics. Note that in Markdown, word-internal underscores are not interpreted as italics (probably to avoid more unnecessary italics in unformatted code and file names), unlike emphasis created with asterisks.

To fix this in the answer, declare the language in the code fence (or none), like I've done above:

```html
<code data-highlighted="yes" class="hljs language-markdown">
```
5

Short answer: this is as resolved as it can be without the company doing some development work on syntax highlighting. I've changed the assigned syntax highlighting for the , and tags to lang-bash, as requested in 'Syntax highlighting: Use "lang-bash" (or similar) as default language for tags [powershell] and [powershell-core] until PowerShell is fully supported' Please see that question and the questions it's linked to for more information.

Laurel has given a good explanation of the reason from within that post that the specific text was in italics, which is that the syntax highlighter was using Markdown as the language for that code block.

There's a larger context, which is the question of "why was the syntax highlighter using Markdown for a code block on that page when the tags on the page clearly indicate that the question is about PowerShell?" The reason that was happening is that the code that decides which languages to have as possible syntax highlight languages on a particular question page. Which language or languages are used depends on the "Code Language" that has been set for the tags used on the question. The last time I looked at the logic, it was that if, and only if, across all the tags on the question there is a single language defined, other than "", then that language is used. The same language being defined on multiple tags counts as a single language. If across the question's tags, there's no language defined, more than one language defined, or the "default" language is set, then "default" is used.

When "default" is used for the syntax highlighting on a page, a group of several languages are used (e.g., HTML, JavaScript, CSS, Markdown) which is a subset of all the syntax highlighting languages Stack Exchange makes available, which is a subset of the languages available for highlight.js. For all code blocks where the syntax highlighting language isn't explicitly specified for the code block, the syntax highlighter separately runs each code block on the page through syntax highlighting for each of that "default" group of languages and chooses to display the language that gets the best "quality/match score". In the case of the code block you were asking about, that ended up being Markdown, which, obviously, isn't correct.

So, the next question is probably "Why wasn't 'Syntax highlighting: Use "lang-bash" (or similar) as default language for tags [powershell] and [powershell-core] until PowerShell is fully supported' implemented a long time ago. Unless a moderator is a Subject Matter Expert (SME), who might rely on their expertise to make a call for that technology, then such requests are generally not implemented unless the question gains some amount of community consensus, which sometimes takes time. Moderators don't, generally, track the progress of such requests, but we do tend to look at them when they show up in the active questions list. We also, of course, look at them when someone flags the question requesting that we evaluate it for implementation. Essentially, it fell off the radar prior to it having a reasonable consensus and nobody flagged it for our attention. The overall situation was brought back to my mind when I saw your question. I had interacted with "Enable automatic and on-demand syntax highlighting for PowerShell (updated for highlight.js)", which was a similar topic, so I was a bit familiar with syntax highlighting on those tags.

1
  • 1
    I didn't even know Markdown was a supported syntax-highlighting option. Commented Sep 10 at 21:22

You must log in to answer this question.

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