52

It would be nice to be able to put emphasis on specific bits of a fragment or of a quote (bold can help for a quote but I find that it makes things less readable sometimes).

What do you think?

Update: On http://www.pastebin.com/, you can highlight particular lines by prefixing each line with @@.

See also:

  • 3
    Really nice idea. I think it may tempt n00bs to abuse it when posting huge chunks of code ("Hey, I highlighted the relevant part!!!"), but that's easily dealt with. – Jon Seigel Jun 20 '10 at 16:45
  • 4
    @Jon As long as they format their code, I'd accept to deal with that :) – Pascal Thivent Jun 20 '10 at 16:57
  • 2
    Very nice indeed, but please not with that unreadable color-combination :) – Georg Fritzsche Jun 21 '10 at 0:23
25

I like the idea.

For highlighting a whole line, one could extend the markdown syntax and define that an asterisk before the four spaces required to highlight a code block highlights that line:

    for ($i = 0; $i <= 1; $i++)
     {  
*      print "$i lines!";  // this line gets highlighted
     }

this would work without having to work out a character or character sequence that turns on highlighting within a block.

  • 1
    First suggestion I've seen that would work. No opposed. – dmckee Jun 20 '10 at 18:34
  • 2
    Not that i think its very important, but could we mark the first line that way too the way SOs markdown works? – Georg Fritzsche Jun 23 '10 at 20:49
  • @Georg no, but arguably the first line is easy to point out in the text body. – Pekka supports GoFundMonica Nov 3 '11 at 19:06
4

What about just breaking up the code block?


You need to use the print function:

function foobar()
{
  for ($i = 0; $i <= 1; $i++)
  { 
    print "$i lines!";
  }
}
  • I'd probably leave out the explanatory text though. The break in the code block would be enough to notice. Writing the explanation that way is harder to read, especially in a larger block of code. You could still leave the explanatory native comment within the block though. – Jeff Mercado Nov 3 '11 at 20:49
  • @Jeff: I like it. See my revised answer – The Unhandled Exception Nov 3 '11 at 20:56
  • I'd leave out the horizontal lines though. You can get away with leaving those out. I'll edit your answer if you don't mind just to show what I mean. Rollback or improve if you wish. – Jeff Mercado Nov 3 '11 at 20:58
  • @JeffMercado Even better, thanks! I couldn't easily figure out how to do that, which is why I was using the <hr>s – The Unhandled Exception Nov 3 '11 at 20:59
  • 1
    It's a work-around. The only thing it highlights is that you can't highlight a line in a code block – Bohemian Feb 14 '14 at 23:37
0

Meh.

IMHO, if a code block is so large that a simple comment like this:

blah.blah.blah(arg, arg, arg);
class.class.method(arg, arg, arg + 1, weird_arg, blah);  // <-- something strange happens here
blah.blah.blah(arg, arg, arg);

...doesn't stand out on its own, then chances are the code block is including too much and the example should be pared down a bit.

  • Well, using comments is what I currently do but 1. you sometimes needs the whole context of a piece of code, 2. comments might not get spotted and 3. I find it limiting, especially when dealing with XML blocks. Not to mention that comments doesn't work with quotes. – Pascal Thivent Jun 20 '10 at 17:03
  • @Ether I disagree. It is often necessary to post a full block of code to make a diagnosis, and being able to highlight the line the compiler/interpreter chokes at would be a good thing. – Pekka supports GoFundMonica Jun 20 '10 at 17:41
  • 4
    @Down: Pare it down: if you can't pare it down you're only guessing about where the trouble is in any case. – dmckee Jun 20 '10 at 18:37
  • 3
    @dmckee I disagree, especially newbies who get a "error x on line 188" often need to show a whole block to make sense, but it would be great to know where line 188 is in all that, which is where the highlighting comes in. But +1 for teaching me a new english word. – Pekka supports GoFundMonica Jun 20 '10 at 20:53
  • 3
    @Down: Maybe it's the teacher in me, but I see that as an opportunity to teach the new programmers that vital debugging skill of isolating the offending code. – dmckee Jun 20 '10 at 23:18
  • 1
    @dmckee: As long as SO is open to beginners there will always be people who can't identify the relevant parts properly. Even non-beginners may have that problem - e.g. plain COM programming carries so much visual noise that its hard to trim or reduce to a few central lines. gtk+ using C is also quite line-hungry. – Georg Fritzsche Jun 21 '10 at 0:27
  • It's not about the size of the block, it's about highlighting that part that matters. – Bohemian Feb 14 '14 at 23:38

You must log in to answer this question.

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