-13

It would be very useful to have some spoiler tags to hide ultra long code or text lines, otherwise users have to scroll for ages even though they are not interested for a specific code, quote or other text part at the moment.

It should be possible to hide it.

e.g. it is not possible to collapse this by default at the moment:

Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus.

add some functionality so that we can only see the first few lines and see the rest only if we click on it, e.g.

<collapse>
> Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
> labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos
> et accusam et justo duo dolores et ea rebum. Stet clita kasd
> gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
> Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
> nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
> sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
> rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
> ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur
> sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et
> dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam
> et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea
> takimata sanctus. 
</collapse>

Result:

Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut
labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos
...

This is common in many forums and would be a nice feature for Stack Overflow

19
  • 2
    That's not code markup, that's quote markup.
    – user247702
    Commented Apr 18, 2017 at 13:39
  • 1
    You claim to have posted an example of a long code snippet, and then shown a long quote, rather than a code snippet. Code snippets, unlike quotes, have a maximum height.
    – Servy
    Commented Apr 18, 2017 at 13:39
  • @Cerbrus does the existing functionality collapse tall quote blocks?
    – user247702
    Commented Apr 18, 2017 at 13:40
  • @Stijn: Is this question in any way clear as to what it wants? Maybe the dupe is not a perfect fit, but don't re-open questions that should be closed any way.
    – Cerbrus
    Commented Apr 18, 2017 at 13:41
  • 1
    @Cerbrus Somewhat, although OP should clarify a bit. But at least we can deduce that OP wants to have long blocks of text collapsed by default, similar to spoiler feature as often seen on phpbb-like forums. So I wouldn't call it an exact duplicate of that post.
    – user247702
    Commented Apr 18, 2017 at 13:45
  • Yes, thats exactly what I asked for @Stijn What is the reason for calling this duplicate?
    – Black
    Commented Apr 18, 2017 at 13:46
  • Looking at the title, it's a perfect duplicate. I don't intend to re-open this myself until the question is made clear, and the obnoxious Iorem Ipsum is removed.
    – Cerbrus
    Commented Apr 18, 2017 at 13:46
  • @Black I'm confused. Long blocks of code get scroll bars already (random example), and so the issue is avoided. Are you asking for scroll bars in long blocks of non-code? Is that what this is about?
    – Jason C
    Commented Apr 18, 2017 at 13:48
  • I am asking for a function to hide any block, text or code. This is common in many forums.
    – Black
    Commented Apr 18, 2017 at 13:49
  • Old feature request here on MSE, similar to this question, that was declined.
    – user247702
    Commented Apr 18, 2017 at 13:50
  • @Black But you mention wanting some sort of "spoiler tags" to do this. Are you asking for this to be provided automatically and globally for every block of text? Or are you asking for some sort of tag by which the author of a post can explicitly indicate that they want that to happen for that text?
    – Jason C
    Commented Apr 18, 2017 at 13:50
  • @JasonC, yes there should be new tags e.g. <collapse></collapse> Otherwise there are posts which are extremly long
    – Black
    Commented Apr 18, 2017 at 13:51
  • @Black basically what you are looking for is something like the way we can hide snippets right? That can be applied to anything - code, quotes and/or text
    – CalvT
    Commented Apr 18, 2017 at 13:53
  • @Black: I wouldn't count on SE adding new "html", or markdown tags. Both markup languages are standardized, and preferably not messed with.
    – Cerbrus
    Commented Apr 18, 2017 at 13:53
  • 2
    @CalvT Fwiw, I will always remove snippet tags when I see them used with languages that snippets do not support (e.g. C++).
    – Jason C
    Commented Apr 18, 2017 at 14:00

4 Answers 4

0

There's no need to invent a new tag. <details> exists and is widely supported.

GitHub supports it within markdown prose and SO could do the same.

It's pretty simple to use:

<details>
  <summary>Here's my giant example</summary>
    Dantooine. They're on Dantooine. Alderaan? I'm not going to Alderaan. I've got to go home. It's late, I'm in for it as it is. I care. So, what do you think of her, Han? All right. Well, take care of yourself, Han. I guess that's what you're best at, ain't it?
    I call it luck. The plans you refer to will soon be back in our hands. Look, I ain't in this for your revolution, and I'm not in it for you, Princess. I expect to be well paid. I'm in it for the money.
    What?! I need your help, Luke. She needs your help. I'm getting too old for this sort of thing. Oh God, my uncle. How am I ever gonna explain this? Hokey religions and ancient weapons are no match for a good blaster at your side, kid.
    As you wish. Don't be too proud of this technological terror you've constructed. The ability to destroy a planet is insignificant next to the power of the Force. You mean it controls your actions? He is here.
</details>

1
10

Please don't add new markdown / "html" tags.

These languages are standardized, and we shouldn't be adding new functionality to them like that.


7 years later, now there's <details>.

This tag isn't supported on SE at the moment, so would require an addition/extension of SE's HTML parser.

The result is that you have hidden text in a question, making it easier to post spam.

If something is important enough to write in your answer, don't hide it.
If something is unimportant enough that it can be hidden, why add it at all?

7
  • The html tags were just an example, of course they can use something else like § block §...
    – Black
    Commented Apr 18, 2017 at 13:56
  • 8
    § isn't on my keyboard. And that'd be a addition to markdown that could break existing posts.
    – Cerbrus
    Commented Apr 18, 2017 at 13:57
  • LOL, § was also just an example.
    – Black
    Commented Apr 18, 2017 at 14:14
  • 4
    You're, missing my point, @Black. We can't just add a new keyword / character / tag to markdown like that.
    – Cerbrus
    Commented Apr 18, 2017 at 14:15
  • I don't see a reason why we can't add one.
    – Black
    Commented Apr 18, 2017 at 14:16
  • 10
    Because it could break existing questions / answers that contain said keyword / character / tag, @Black.
    – Cerbrus
    Commented Apr 18, 2017 at 14:17
  • No new tag needed. <details> exists and is widely supported.
    – Jacktose
    Commented Sep 10 at 19:26
7

I disagree with this feature request.

While I agree that collapsible code and quotes may be useful, I don't think it should be left up to the author to choose what that applies to (and most wall-of-code posters aren't going to do that anyways, you'll just end up having to edit it in all the time), and I don't think it should involve new tags. The best case result I can see there is tons of people using/not using the collapse tags in different but equally irritating ways.

In any case, if you're using Chrome, in the mean time check out https://stackapps.com/questions/6753 - it has a collapse feature, only for code, but perhaps you could make a PR or ask the author for new features. Also search around on StackApps, there may be other things that work for you.

A user script for this should be straightforward as well, if you are so inclined. If you do, share it on https://stackapps.com, I'm sure there are others who would find it useful.


Here is a really crappy user script that I threw together that adds a collapse/expand link above all quotes and code blocks:

// ==UserScript==
// @name         Collapsible Text Blocks
// @namespace    http://stackexchange.com/users/305991/jason-c
// @version      1.0
// @description  Adds collapse/expand links to text blocks
// @author       Jason C
// @include http*://*.stackexchange.com*
// @include http*://*.stackoverflow.com*
// @include http*://stackoverflow.com*
// @include http*://*.superuser.com*
// @include http*://superuser.com*
// @include http*://*.serverfault.com*
// @include http*://serverfault.com*
// @include http*://*.stackapps.com*
// @include http*://stackapps.com*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var EXPAND_TEXT = "Expand";
    var COLLAPSE_TEXT = "Collapse";
    var contentId = 1; // tracks block ids

    // comment this out if you don't want to apply to blockquotes
    $("div.post-text blockquote").each(function () { makeCollapsible(this); });

    // comment this out if you don't want to apply to code
    $("div.post-text pre").each(function () { makeCollapsible(this); });

    // ------------------------------------------------------------------------------

    window.collapseHandleClick = function (link, id) {
        var content = $(`#collapse-content-${id}`);
        content.slideToggle(function () {
            link.innerHTML = (content.css('display') == 'none') ? EXPAND_TEXT : COLLAPSE_TEXT;
        });
    };

    function makeCollapsible (el) {

        // the collapse link will be added to the blockquote
        var collapse = document.createElement("div");
        collapse.style.fontSize = "80%";
        collapse.style.position = "absolute";
        collapse.style.marginTop = "-2.8ex";
        collapse.style.background = "rgba(255, 255, 255, 0.25)";
        collapse.innerHTML = `<p>[ <a href="javascript:void(0)" onclick="collapseHandleClick(this, ${contentId})">${COLLAPSE_TEXT}</a> ]</p>`;

        // the blockquote's normal contents will be moved into a child div
        var content = document.createElement("div");
        content.id = `collapse-content-${contentId}`;
        $(content).append($(el).children());

        el.appendChild(collapse);
        el.appendChild(content);

        ++ contentId;
    }

})();

It makes it look like this.

5

No, I don't see reason why I'd want to have half of the post hidden.

We already require MCVE for code and have remove fluff policy to deal with text not related to the problem/solution. As result of both what stays in the post is necessary to understand question or answer - hiding it would lead reader to wrong path.

As for ways to handle - usually it is taken care naturally - people are less interested to read long posts with a lot of unrelated information resulting in at least lower vote count and sometimes downvotes (or VTC as unclear for questions). You may consider editing out obviously unrelated content or excessive samples, but such edits have good chance to be viewed as too major and rejected/reverted. Comments to OP would be better.

You must log in to answer this question.

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