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>
>! `indented line`<br>
>! `another indented line`<br>
>! `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.
-
\$\begingroup\$ spoiler markdown is one of these beasts... \$\endgroup\$Vogel612– Vogel6122015年07月09日 23:19:04 +00:00Commented 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\$Simon Forsberg– Simon Forsberg2015年07月09日 23:23:41 +00:00Commented Jul 9, 2015 at 23:23
-
\$\begingroup\$ meta.stackexchange.com/a/166004/148099 \$\endgroup\$200_success– 200_success Mod2015年07月10日 05:46:39 +00:00Commented Jul 10, 2015 at 5:46
-
\$\begingroup\$ meta.stackexchange.com/q/217779/148099 \$\endgroup\$200_success– 200_success Mod2015年07月10日 05:46:59 +00:00Commented Jul 10, 2015 at 5:46
-
\$\begingroup\$ Why are we posting code inside spoilers? \$\endgroup\$nhgrif– nhgrif2015年07月11日 22:34:09 +00:00Commented 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– Caridorc2015年07月12日 09:45:16 +00:00Commented 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– nhgrif2015年07月12日 11:47:17 +00:00Commented 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\$Simon Forsberg– Simon Forsberg2015年07月12日 11:49:03 +00:00Commented Jul 12, 2015 at 11:49
-
\$\begingroup\$ That's why I haven't posted an answer... \$\endgroup\$nhgrif– nhgrif2015年07月12日 11:51:44 +00:00Commented Jul 12, 2015 at 11:51
1 Answer 1
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!"; }