11

Sometimes I use HTML <pre><code>…</code></pre> instead of Markdown ```…``` / ␣␣␣␣… blocks for code blocks with inline text formatting. I have noticed recently that such inline formatting is now stripped out by the automatic syntax highlighting on Stack Overflow.

Can this be reverted so that the formatting is preserved?

(What follows is just my reasoning and some examples.)

Other prolific and eminently helpful users like Willem van Onsem also use this type of formatting very often, and this change disrupts important elements of the presentation of many of their answers, while I think it’s important that it be preserved. Furthermore, inline formatting is more accessible to screenreaders than strictly visual workarounds like underlining with comment delimiters, even without using semantic HTML tags. (I’d certainly be happy if support were added for them, but that can be a separate feature request.)

On my recent answer, in the editing preview as well as the rendered post, I noticed that using a <pre> + <code> block with syntax highlighting enabled would strip out the formatting tags. As a workaround there (and in this post) I’ve used <!-- language: lang-none -->, which is okay sometimes but not ideal in general.

I typically use inline formatting of code in the following situations:

  1. I want to draw attention to a section of the code as either important or non-verbatim in some way (user- or programmer-specified) using respectively <strong> and <em>, the latter because the semantic <var> is not supported.

    two = numeric expression
    four = two + two
  2. I want to use <a> to add inline links to documentation for functions and types used in the example.

  3. I want to illustrate a “diff” to the code in the question, typically using the <strong> tag and deprecated <strike> tag, because while the semantic <del> tag is supported by the CSS, the matching <ins> is not.

    two = 2
    four = 5  -- You had a typo here.
    four = 4
    main = print (two + two == four)
    

    I have tried to use diff/patch highlighting as a workaround, but these are not enabled languages for syntax highlighting. Also, without some special treatment like copy/paste support, I consider this less suitable for the kind of beginner question I tend to answer this way (e.g. to correct several minor syntax errors without taking a lot of space).

4
  • <!-- language: lang-none --> is no longer supported. At best use <!-- language-all: lang-none --> at the start of your post.
    – rene
    Commented Jul 1, 2021 at 21:37
  • 2
    @rene Citation required. When did that change? I've used that exact syntax when editing posts fairly recently, and it's worked fine (except with the new editor on Teams/Articles, where it is stripped out upon attempting to edit a second time, but still seems to render).
    – Cody Gray Mod
    Commented Jul 1, 2021 at 23:49
  • 1
    @CodyGray when they switched to common mark. I happened to have an answer on that topic when Common Mark was announced: meta.stackexchange.com/a/348754/158100
    – rene
    Commented Jul 2, 2021 at 5:24
  • 5
    This post by a staff describes the underlying issue that is causing this, which is highlight.js stripping HTML tags. Commented Jul 5, 2021 at 18:26

0

You must log in to answer this question.

Browse other questions tagged .