107

Following the Do we want the “spoiler” feature turned off? thread on meta.tex.sx, it's clear that the spoiler markup has a wrinkle or two that I didn't at first appreciate. For information's sake, the spoiler feature is contentious because it collides with the syntax for Latex errors.

Is there a precise description of when a blockquote will be treated as a spoiler?

Two related threads containing some information on the syntax:

  1. Implement the <spoiler> tag
  2. Add markdown support for hidden-until-you-click text (aka spoilers)
4
  • This is by no means an answer but I was playing with it in the formatting sandbox and found that if you insert a blank line anywhere within the block quoted text, the spoilers are completely disabled for that block. Could be used as a temporary workaround until the feature is refined or is otherwise changed. Commented Dec 21, 2010 at 8:58
  • @Jeff - that is intended behavior. If a blockquote contains a line that doesn't start with a ! its not a spoiler. Commented Dec 21, 2010 at 9:06
  • Likewise, you can throw in some non-rendered content on an extra > line that will be ignored, and it'll prevent the spoiler-fication (since it's just a blockquote then).
    – Tim Stone
    Commented Dec 21, 2010 at 9:06
  • This question has been closed as a duplicate of the original feature request, meta.stackexchange.com/questions/1191/… - the Q&A thread is a kind of workshop for possible syntaxes and the hightes-voted answer gives the basic idea of how the feature is used. The question does not ask for syntax, and no answer considers tricky cases, so that thread in no sense answers the question asked here. Vote to reopen - if new quirks emerge, it is possible this thread might be useful in documenting them. Commented Dec 13, 2019 at 16:23

1 Answer 1

119

The way spoiler works is as follows.

If each line in a blockquote (built via >) begins with a ! it will be treated as a spoiler.

So,

>! This is a spoiler

This is a spoiler

>! But this is  
> not a spoiler

! But this is
not a spoiler

>! A multi-line spoiler  
>! has ! multiple times

A multi-line spoiler
has ! multiple times

>! Alignment  
> ! has no effect  
 >  ! on spoilers  

Alignment
has no effect
on spoilers

Due to wrinkle in how blockquotes are generated, leading white space is pretty pointless.

> ! <- still a spoiler

<- still a spoiler

The actual code expects very specific html (this a "post markdown" process). In particular, omitting the inner <p> will dodge "spoiler-ification".

The only way to guarantee a blockquote becomes a spoiler is to use the explicit >! syntax.


Prior to implementing this, I did actually check for posts that would be affected by this syntax (on SO its under one-tenth of a percent*). Even on TeX, (where ! is rather likely to come up as a first character) it is exceedingly rare (lower than SO levels). People seem very biased towards using code tags.

I'm not saying there aren't any, but any new syntax is going to catch somebody.

*Admittedly, I'm regex-ing wildly through lots of data, there is some room for error. Pretty sure I'm erroring on the side of over counting affected posts, though.

9
  • Do the !s have to be vertically aligned? Commented Dec 21, 2010 at 8:59
  • @Charles - no, they just need to be the first non-whitespace character after the >. Commented Dec 21, 2010 at 9:01
  • 2
    I tried to add an image in the spoiler, but the image is always shown. Only text is hidden. I added this: ` >! Spoiler ![Image description][3] Hello`. The text "Spoiler" and "Hello" was only shown on mouseover, but the image in the middle was shown always.
    – awe
    Commented Sep 11, 2012 at 8:52
  • 1
    The multi-line spoiler isn't working for me. It's all on one line.
    – Tony Ennis
    Commented Nov 20, 2015 at 3:35
  • 2
    @awe >! [![image][1]][1] this works in image, and image description [1]: https://i.sstatic.net/9BTi2.jpg
    – J M
    Commented Sep 14, 2017 at 5:43
  • 6
    This actually just works as a hover but is there a collapsable spoiler in markdown? Commented Nov 22, 2017 at 11:28
  • 1
    Absurd syntax, because pretty long to write for a long spoiler (one of the use of a spoilder, hidding long to read info), but anyway, doesn't work anymore it seems!
    – Quidam
    Commented May 2, 2020 at 5:09
  • I couldn't make a spoiler for a few lines, it gives this error: Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon Commented Feb 7, 2021 at 14:00
  • 3
    What about spoiler for code block?
    – vanowm
    Commented Oct 4, 2021 at 13:07

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