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 sometimes find I want to put a whole codeblock into spoiler text. This is useful in answering homework tagged questions, where I intend to say something along the lines of Now try and implement this part yourself, and mouseover the section below for some ideas if you get stuck. Forgive me if this has been covored before, I searched but didn't find the same question and I couldn't see it in the markup advanced help section either.

This is normal text

This is spoiler text

This is one line of visible code

This is one line of invisible code

def visible_function():
  print 'hello world'

But can I get a multi-line code block that is invisible? I couldn't figure out the markup syntax for it.

def invisible_function():
  print 'Eeek! I feel so naked!'
share|improve this question
This still does not seem to be possible, on SO at least, and… does not seem to have been resolved. I'd love to be able to give answers on SO using this technique from Math. – Jason C Mar 22 '14 at 17:00
up vote 17 down vote accepted

You can do it using HTML

>! <pre><code>def invisible_function():
>!   print 'Eeek! I feel so naked!'</code></pre>

This results in some extra padding, though.

def invisible_function():
   print 'Eeek! I feel so naked!'

share|improve this answer
I tried your approach on SO but it didn't work:-( – Christoph Mar 15 '12 at 16:59
Doesn't work on math.SX, either. – JeffE Apr 30 '12 at 12:42
@Christoph: It looks like the CSS for spoilers conflicts with the syntax highlighting (which is disabled here). – hammar Apr 30 '12 at 12:59
@Christoph, there's a bug report for that: Code samples inside of spoilers are still visible on some sites. – Arjan Feb 2 '13 at 19:03
This does not work if you use <> in the code, e.g. <pre><code>#include <stdio.h></pre></code> or <pre><code><i>text</i></code></pre> – ace May 21 '15 at 13:15
@ace: You can use &lt; and &gt; to escape them. – hammar May 21 '15 at 15:32
this worked for me in Anime.Stackexchange here… – Myk Agustin Feb 10 at 8:59

This may not be the right way to do this. I was just trying different combinations with the syntax and came up with one possible way to include multiline code within the spoiler section using the HTML <pre> tag.

By default, the text is not shown as per spoiler behavior.

text hidden

Multiline code displayed onmouseover.

multiline code


FROM  dbo.Spoiler
WHERE NumberOfLines > 1

share|improve this answer

You must log in to answer this question.

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