13

This question already has an answer here:

I've just answered a question in SO where I had to post four snippets of XML (yes, it was a JavaEE question, how did you guess?)

I made an effort to keep the snippets short and meaningful, but all this code can clutter the visuals of the page, and moves attention away from the rest of the answer.

The site can already detect which parts of the question or answer are code, and paints them in a different font and background. What if it could also add a small toggle button that hides/display each snippet of code?

An example. Displayed: A crudely drawn image of a widget whose purpose is to collapse a block of code, complete with an arrow pointing to this widget and a description "button to hide snippet" of said widget.

Hidden: The same widget as before, only this time it is in a different state and the associated block of code has been truncated according to the requested feature's behaviour. An arrow continues to point at the widget but it is accompanied by another arrow pointing out that an ellipsis (...) symbol should be used to indicate the aforementioned truncation has taken place.

Please acknowledge my superior Photoshop skillzs.

marked as duplicate by gnat, S.L. Barth, Patrick Hofman, ShaWiz, Fish Below the Ice Jul 21 '15 at 12:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • It's a bit of a clunkily edited question, but this proposal which asks for code collapse (and then some) has been denied. – Grace Note Nov 24 '10 at 19:26
  • @26: you've inflicted superfluous "u"s on blind people yet again! Why do you hate the blind so? – Shog9 Nov 24 '10 at 20:16
  • 1
    @shognine: I appeal to only the most Canadian of blind people. The blind people of lesser countries will have to make do. – Welbog Nov 24 '10 at 20:17
  • @26: Aye. A thousand apologies. I promise I'll be more careful next time. – Leonel Nov 24 '10 at 20:36
  • 1
    Aside: the site does not "detect" code, it provides a formatting option for code (well, two one for inline and one for blocks). – dmckee Nov 24 '10 at 21:12
11

For the record, this now exists (at least for some languages).

<!- begin snippet: js hide: true -->

<!-- language: lang-js -->

alert(2+ 40);

<!-- end snippet -->

Note: because of the way HTML-comments work here, you'll need to add an extra '-' inside the first comment-tag for that to work.

When you do it, it will look like:

alert(2+ 40);

  • 1
    but what if i want to hide a sample response of some code/command? "Show code snippet" is not what it should say – joey baruch Nov 22 '17 at 9:17
  • @joeybaruch You really should be able to put your own text in there. I think at least that it's obvious it's a dropdown. Then you can name each of the dropdowns something like 'index.html', 'main.css', 'main.js' – Jacob Jun 28 at 10:11

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