1 / 3
Shog9
  • 101
  • 5

I apologize in advance for the English-language answer; I'll ask Aki to translate when she's available.

The crux of the problem here is that spoilers are a Stack Exchange-specific extension to the core Markdown syntax; as such, they don't interact well with other forms of markup. In this case, they don't work well with code formatting: if they did, you'd be able to write a code spoiler just as you might wrote a blockquoted spoiler.

For a normal quote block, this Markdown:

>     int main() {
>         printf("Hello, world!\n");
>         return 0;
>     }

...produces this result:

int main() {
    printf("Hello, world!\n");
    return 0;
}

But this doesn't work:

>!     int main() {
>!         printf("Hello, world!\n");
>!         return 0;
>!     }

...The results aren't formatted as code. This is why the recommendation on Meta Stack Exchange is to use HTML to format the code. However, the example there doesn't work well here because of this site's insertion of <br> newlines.

The proper solution (which can be used everywhere) is to trick the spoiler processor into treating a normal blockquote as a spoiler, by inserting an exclamation point (!) at the start of each line within the spoiler paragraph:

So this HTML:

<blockquote><p>
!<pre><code>int main() {
!    printf("Hello, world!\n");
!    return 0;
!}</code></pre>
</p></blockquote>

Produces this result:

int main() {
    printf("Hello, world!\n");
    return 0;
}

To use this effectively, you'll need to manually escape any code that interferes with the parsing of the HTML markup - for example, & must become &amp;, < must become &lt;, etc.

Shog9
  • 101
  • 5