13
\$\begingroup\$

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.

\$\endgroup\$
9
  • \$\begingroup\$ spoiler markdown is one of these beasts... \$\endgroup\$
    – Vogel612
    Jul 9, 2015 at 23:19
  • 2
    \$\begingroup\$ Suddenly I get the feeling this might end up as a bug, or feature-request, or a duplicate of some post on MSE... \$\endgroup\$ Jul 9, 2015 at 23:23
  • \$\begingroup\$ meta.stackexchange.com/a/166004/148099 \$\endgroup\$ Jul 10, 2015 at 5:46
  • \$\begingroup\$ meta.stackexchange.com/q/217779/148099 \$\endgroup\$ Jul 10, 2015 at 5:46
  • \$\begingroup\$ Why are we posting code inside spoilers? \$\endgroup\$
    – nhgrif
    Jul 11, 2015 at 22:34
  • 2
    \$\begingroup\$ @nhgrif code-review teaches to fish, it does not give fish, giving a fish inside spoiler tags may help future visitors though. \$\endgroup\$
    – Caridorc
    Jul 12, 2015 at 9:45
  • \$\begingroup\$ 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. \$\endgroup\$
    – nhgrif
    Jul 12, 2015 at 11:47
  • \$\begingroup\$ @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. \$\endgroup\$ Jul 12, 2015 at 11:49
  • \$\begingroup\$ That's why I haven't posted an answer... \$\endgroup\$
    – nhgrif
    Jul 12, 2015 at 11:51

1 Answer 1

8
\$\begingroup\$

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

>! <pre>
>! if(solution.SolutionBad == "possibly") {
>!     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") {
>!     print "Code in spoilers!";
>! } </pre>

Output:

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

\$\endgroup\$

You must log in to answer this question.

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