Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 158 Stack Exchange communities.

What is meta?
Here's how it works:
  1. Any Stack Exchange user can ask a question
  2. The community provides support, votes on ideas, and reports bugs
  3. Your voice helps shape the way Stack Exchange operates

I quite frequently would like to have parts of code work as links (e.g. uncommon methods linking to relevant documentation). Achieving that is possible with HTML <pre> and explicit <a> tags; however, the syntax highlighting doesn't seem to work on these manual <pre> blocks. Is there a way to have both?

share|improve this question
up vote 5 down vote accepted

If you're really up to it, you can enclose a <code> tag inside the <pre> tag. We don't have syntax highlighting here on Meta, so you can't see it, though.

I caution against this, even though it works. Most people probably will not expect hyperlinks to be inside code blocks because most programs don't include functional hyperlinks in their bodies, so it will not be as intuitive to readers as including the hyperlink before or after your code not unlike what you did here.

if (true) {
    WebObject R = 9;
} else {
    Hyperlink B = 5;

if (true) {
    WebObject R = <a href="">9</a>;
} else {
    <a href="">Hyperlink</a> B = 5;

For a demonstration of how it looks on Stack Overflow, here's an image. Notice how the hyperlink has the same color as a standard formatting for both the number and the type. It's not at all visible that it is a hyperlink. I did test this on an actual post, and the rendering is the same as the preview. But I probably should've done it as an edit suggestion, since that would've been properly rejected. Ah well.

Shows source code for this, and the rendering on Stack Overflow.

share|improve this answer
I didn't know this!! nice! – Trufa Feb 8 '11 at 14:32
Would it be worth having some styling support as a feature request? – Jakub Hampl Feb 8 '11 at 16:56
@Jakub People still won't expect hyperlinks in the code block, and furthermore, wouldn't that break the syntax highlighting that you're gunning for? If you still want to make a feature request to see what people at large thing, please feel free to do so. My own thought is that it won't get much headway, though. – Grace Note Feb 8 '11 at 16:59
Well I thought that having something underlined (though not necessarily in link color) makes it kind of obvious. Also quite a few web syntax highlighters do this automatically and can be really helpful for beginners. – Jakub Hampl Feb 8 '11 at 17:02

You must log in to answer this question.

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