-8

In this question, I mention something which does not work in a code block.

For readability reasons, I'd like to put this in red colour (either the font of the background). I don't mean the entire code block, but just a limited part (one line in this case).

How can I do this?

6
  • Guys, please. As mentioned in my comment on the accepted, this is a correct, well-justified question. Three downvotes in just fiveteen views is really overkill.
    – Dominique
    Commented Apr 2, 2021 at 10:36
  • 1
    For demonstrate some textual explanations of the the output, I would prepare a small screenshot of that output with modifications like underscoring the undesired words, comments for that, etc. Assuming your question post contains a textual output and textual explanations why this output is not desired, the additional image doesn't contradict to SO rules.
    – Tsyvarev
    Commented Apr 2, 2021 at 10:37
  • 2
    These downvotes just express others' disagreement with your feature request.
    – Tsyvarev
    Commented Apr 2, 2021 at 10:45
  • @Tsyvarev: thanks, I updated my question accordingly.
    – Dominique
    Commented Apr 2, 2021 at 11:01
  • 2
    Yes, "feature-request" tag seemed to be not needed: nothing in your post express intention to add something into SO system. But note, that even for non-feature-requesting questions downvotes-as-disagreement are still possible: meta.stackoverflow.com/questions/406288/…. In your case a downvote could mean "I don't like an idea to make a colored code block". Generally, you could ignore downvotes on meta :)
    – Tsyvarev
    Commented Apr 2, 2021 at 11:13
  • Say what you can say using text by using text. You are asking how to do something that you shouldn't do. meta.stackoverflow.com/q/285551/3404097. Use images / visual effects only for what cannot be expressed as text or to augment text.
    – philipxy
    Commented Apr 2, 2021 at 13:06

2 Answers 2

8

That is not possible.

At best you can handcraft a code block in pure (allowed) HTML and make lines or characters bold by wrapping things in a <b></b> tag:


  void Main() {
     int** i++; // don't do this
     for(i=0 ; i < 10 ; i++) {
        a = a + &i;
     }
  }

but that is about it. Style attributes or CSS classes are not supported on the allowed HTML tags within an Stack Overflow post.

Above code block looks like this in markdown:

<pre>
<code>
  void Main() {
     <b>int** i++; // don't do this</b>
     for(i=0 ; i &lt; 10 ; i++) {
        a = a + &i;
     }
  }
</code>
</pre>

Just for the record: I don't think adding or using colors should be made possible. I don't fancy Stack Overflow posts to light up as a Christmas tree. The allowed use of Emoji is worse enough. Let's not TikTok down that rabbit hole.

3
  • 3
    Thanks for the quick reply. I'm really not interested into changing pieces of code into colourbooks :-) I just wanted to show the one line in the source code what my problem is all about.
    – Dominique
    Commented Apr 2, 2021 at 10:35
  • @Dominique Then you better tag your question as support and not feature request. The latter is interpreted as if you want to add that feature to SO proper.
    – rene
    Commented Apr 2, 2021 at 10:48
  • Ok, I've re-tagged my question for reference purposes.
    – Dominique
    Commented Apr 2, 2021 at 11:01
3

If it's one line you want to emphasize, use a comment on that line. This way it doesn't affect anyone copying the code:

for(i=0 ; i < 10 ; i++) 
    a = a + &i;  // PROBLEM HERE

If it's more than that, you can either wrap the block with comments, or post it separately:

// PROBLEM STARTS HERE
for(i=0 ; i < 10 ; i++) 
    a = a + &i;
// PROBLEM ENDS HERE

Or:

This is my code:

void Main() {
    int** i++; // don't do this
    for(i=0 ; i < 10 ; i++) {
        a = a + &i;
    }
}

My problem is here:

for(i=0 ; i < 10 ; i++) {
    a = a + &i;

Sorry for stealing your code example rene ;)

1
  • This is what I usually do (also in the question I refer to), I was just wondering if there was a clearer way to do this.
    – Dominique
    Commented Apr 2, 2021 at 10:38

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