Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add collapsable answers #1422

Open
SouthKoreaLN opened this issue Sep 23, 2024 · 9 comments
Open

Add collapsable answers #1422

SouthKoreaLN opened this issue Sep 23, 2024 · 9 comments
Labels
difficulty:easy feature new product features that weren't there before

Comments

@SouthKoreaLN
Copy link
Contributor

Is your feature request related to a problem? Please describe.
Nothing important, nothing frustrating. Just thought that if I want to keep posting puzzles like this one, it'd be nice to have a way to collapse an answer to hide spoilers. But then again, unlikely this will ever be the primary use of SN, so I won't care much if it does not get implemented :)

Describe the solution you'd like
Something like what is illustrated here: https://gist.github.com/pierrejoubert73/902cc94d79424356a8d20be2b382e1ab

Describe alternatives you've considered
Alternative: just ask people not to look at the answers before replying.

@SouthKoreaLN SouthKoreaLN added the feature new product features that weren't there before label Sep 23, 2024
@kravhen
Copy link
Contributor

kravhen commented Oct 14, 2024

Would something like a simple spoiler concealer like this work?
image
sn-spoiler-tag

This would use the existing rehype stylers and CSS method for custom tags.

Other options to make it look like a real <details>+<summary> HTML element as in the gist seems like it'd require a clunkier solution that might not be necessary, like defining a Spoiler component or something.

For the purposes mentioned, the first option seems preferable to me.

Thoughts?

@SouthKoreaLN
Copy link
Contributor Author

This would look like it fits my purpose... as a user, this would just require me adding some tags around the part that needs to be concealed?

@kravhen
Copy link
Contributor

kravhen commented Oct 14, 2024

Yup, you would write it <spoiler>like this</spoiler>. Maybe <hide> to make it shorter.

@SouthKoreaLN
Copy link
Contributor Author

For me, this would work, if it works for larger blocks of text too.

@huumn
Copy link
Member

huumn commented Oct 14, 2024

To support more use cases, I'd prefer a more generic approach like github's details.

like this

This was made with the following markdown:

<details>
    <summary>like this</summary>

This was made with the following markdown:
[...]
</details>

@SouthKoreaLN
Copy link
Contributor Author

SouthKoreaLN commented Oct 23, 2024

Darthcoin gave an interesting suggestion about having to pay to view the answer. Not fully convinced yet as I was just thinking of adding an extra click before one sees the answer, but in the case this suggestion makes sense, it would be best then to have the sats go to the stacker who posted the hidden answer. This might add a layer of complexity though to this issue.

EDIT: on second thought, I don't think I'd want to get people to pay. If people want to see the answer, they should always be free to do so. It's also instructive and possibly entertaining to see answers from smarter people than oneself. One should not have to pay to do that. In the end, it's just about not spoiling the people who want to give the puzzle a genuine try.

@kravhen
Copy link
Contributor

kravhen commented Oct 26, 2024

Should have some time this weekend to give this another try. What bothers me about this is it seems to get behavior consistent with github's, with the details and summary tags and all, it would require rehype-raw (+ rehype-sanitize for good measure).
These are plugins that were successfully avoided previously when enabling support for sub and sup.

An alternative could be to use custom syntax that looks something like:

::: spoiler Click to reveal
# Some hidden text
:::

The drawback I see here is some loss of consistency. There would be support for some tags as expected and familiar for Markdown & HTML, and also some other tags using a custom syntax that users may not be aware of.
If going that route, it may become useful to add another widget next to the markdown helper, or a mouseover, that reveals the SN-specific syntax and future post functionality that is supported.

Besides that, I'm wondering if it'd be possible to create a react component to emulate the collapsible section behavior as closely as possible and render that in posts instead. Typing <details> could render a Details component rather than HTML, assuming naming it the same as a real tag doesn't cause issue or sanitization.

To be continued

@huumn
Copy link
Member

huumn commented Oct 26, 2024

It should be able to be done without rehype-raw. I highly recommend asking claude or chatgpt with the context of rehype-sn

@kravhen
Copy link
Contributor

kravhen commented Oct 26, 2024

You are correct! PR coming shortly.
edit: later tonight or tomorrow... or as soon as I can :')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty:easy feature new product features that weren't there before
Projects
None yet
Development

No branches or pull requests

3 participants