# How can I post code within spoiler markdown?

In a recent answer on a recent question there was code written within a spoiler. I edited the post a bit to format the markdown better, but I ended up with something that just looks... horrible...

How can code be written within a spoiler in posts?

What I ended up with was:

>! somefunction<br>
>!  &nbsp;&nbsp;indented line<br>
>!  &nbsp;&nbsp;another indented line<br>
>!  &nbsp;&nbsp;return something<br>
>! end


This shows as:

somefunction
indented line
another indented line
return something
end

but I find that the markdown to accomplish that is really ugly.

• spoiler markdown is one of these beasts... Jul 9, 2015 at 23:19
• Suddenly I get the feeling this might end up as a bug, or feature-request, or a duplicate of some post on MSE... Jul 9, 2015 at 23:23
• meta.stackexchange.com/a/166004/148099 Jul 10, 2015 at 5:46
• meta.stackexchange.com/q/217779/148099 Jul 10, 2015 at 5:46
• Why are we posting code inside spoilers? Jul 11, 2015 at 22:34
• @nhgrif code-review teaches to fish, it does not give fish, giving a fish inside spoiler tags may help future visitors though. Jul 12, 2015 at 9:45
• You can teach to fish without giving the fish and without using the spoiler. I find spoiler sections highly unnecessary and inappropriate on Code Review. Likely, I'd downvote most posts I see with spoiler sections. Jul 12, 2015 at 11:47
• @nhgrif Whether or not to use code inside spoilers is a bit of a different question. This question is focusing on how to do it for those who might want to do it. Jul 12, 2015 at 11:49
• That's why I haven't posted an answer... Jul 12, 2015 at 11:51

Welp. This is the best solution I came up with. If you're okay with using <pre>, then this is probably the best.

>! <pre>
>!     print "Code in spoilers!";
>! }
>! </pre>


Output:

 if(solution.SolutionBad == "possibly") {
print "Code in spoilers!";
}


If you put the closing </pre> on the last line of code, that will remove one extra blank line at the end.

>! <pre>

 if(solution.SolutionBad == "possibly") {
}