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

Initial support for markdown spoiler tags #867

Merged
merged 16 commits into from
Jan 5, 2024
Merged

Conversation

hjiangsu
Copy link
Member

@hjiangsu hjiangsu commented Oct 30, 2023

Pull Request Description

This PR introduces some basic functionality for handling spoiler tags within Markdown. This works by creating a new ExtensionSet which parses spoiler tags, and generates a custom widget for tags defined as spoiler through the use of MarkdownElementBuilder

This implementation doesn't fully follow Lemmy's method of showing spoilers in that it doesn't show the title of the spoiler. However, most other things work as expected now. When there is a spoiler, it will hide it using a spoiler block. You can tap on the spoiler block to show or hide the spoiler.

Note: currently, the spoiler will take up roughly the same amount of space as the actual content of the spoiler. I don't know what the best way to do this is, so if there are any suggestions, that would be great!

When using Lemmy's spoiler tag definition, the spoiler will always be on a new line. This is because Lemmy's spoiler tag definition looks like:

::: spoiler title
body
:::

I've also added unofficial support for doing inline spoiler tags as defined below. Note that this is not an officially supported specification/syntax so it does not work across Lemmy apps. If there ever comes a point where there's a way to define an inline spoiler text, then we can modify the regex to use that spec.

::: spoiler text_of_spoiler :::

Issue Being Fixed

Issue Number: #304

Screenshots / Recordings

Before Tapping After Tapping
simulator_screenshot_89403F89-D59F-4E37-BC74-37F942EAA5CD simulator_screenshot_2DBA15BA-AF1D-445A-93BC-8F9448607FCD
simulator_screenshot_355FBBA0-165F-405C-9EEB-5A6E07ECCC26 simulator_screenshot_BE82D676-73A0-443D-8056-ECE46375AB34

Checklist

  • Did you update CHANGELOG.md?
  • Did you use localized strings where applicable?
  • Did you add semanticLabels where applicable for accessibility?

@micahmo
Copy link
Member

micahmo commented Nov 1, 2023

Hey I thought I had already commented on this PR, but now I can't find my comment. Fortunately I saved it. Here's what I meant to say.


Wow, nice work!! This already looks great!

Unfortunately, either I'm doing something wrong, or it doesn't work quite right on Android. Here's what I see on the post you linked. Some comments are empty, others don't respect the spoiler, etc. Can you try in your Android emulator just to see if I'm crazy?

image

@hjiangsu
Copy link
Member Author

hjiangsu commented Nov 2, 2023

Hmm, that's really interesting. I'll do a test with an Android emulator when I get the chance and see what the issue here is!

@ghost
Copy link

ghost commented Nov 5, 2023

Hmm, that's really interesting. I'll do a test with an Android emulator when I get the chance and see what the issue here is!

i have an android phone(samsung galaxy m21s), if you want me test it on hardware i'm happy to help :b

@hjiangsu
Copy link
Member Author

hjiangsu commented Nov 5, 2023

Unfortunately, either I'm doing something wrong, or it doesn't work quite right on Android. Here's what I see on the post you linked. Some comments are empty, others don't respect the spoiler, etc.

@micahmo I think I figured out the issue - could you try again and see if it works now?

i have an android phone(samsung galaxy m21s), if you want me test it on hardware i'm happy to help :b

@Vilianexe Thanks for the interest! Do you happen to have some prior background in development or know how to set up your environment for development?

If you're curious on how to set up your computer for development or would like to learn how to, you can check out the README. If not, you can wait until this is released as part of nightly build and provide any feedback then!

@micahmo
Copy link
Member

micahmo commented Nov 6, 2023

I think I figured out the issue - could you try again and see if it works now?

Nice! Looking much better now! Let me know if this is what you're expecting.

qemu-system-x86_64_AxK59KHxgO.mp4

A couple quick thoughts...

  • Right now it's not obvious to me that something is a spoiler. I'm not sure if we should have the right arrow symbol like the how HTML renders details or if it should look like a link or something else. Maybe we can see how other apps do it.
  • Also I was thinking we shouldn't have the inkwell effect on the comment (which maybe means the comment would also handle the tap and do a collapse?). Seems like the tap event is leaking through.
  • I was wondering if the title should still be displayed even once the body is expanded.

Otherwise looking great!

@hjiangsu
Copy link
Member Author

hjiangsu commented Nov 6, 2023

Nice! Looking much better now! Let me know if this is what you're expecting.

Yup, that's what I'm expecting! There's definitely some issues with this implementation at this time as I mentioned in the PR description.

Right now it's not obvious to me that something is a spoiler. I'm not sure if we should have the right arrow symbol like the how HTML renders details or if it should look like a link or something else. Maybe we can see how other apps do it.

I agree, we can think of a better way to show that something is a spoiler. What is implemented at the moment is mainly a placeholder since I was more focused on the overall logic first. I can add in an arrow to make it a bit more obvious. If you have any screenshots of how other apps do it, it would be great!

I was wondering if the title should still be displayed even once the body is expanded.

I can do that!

Also I was thinking we shouldn't have the inkwell effect on the comment (which maybe means the comment would also handle the tap and do a collapse?). Seems like the tap event is leaking through.

Could you clarify a bit more what you mean here?

@micahmo
Copy link
Member

micahmo commented Nov 6, 2023

If you have any screenshots of how other apps do it, it would be great!

Well Boost doesn't support at all! 😆

Jerboa looks very much like the web (makes sense).

scrcpy_aIgzmEiv8b.mp4

Sync has an interesting implementation. It's not quite right, because it doesn't show the title before revealing, and there's no way to unreveal, but I do like the idea. It covers the spoiler in a solid block until revealed. I do think that makes it very clear that there's a spoiler. What do you think?

scrcpy_17LnVvqFZ9.mp4

Also I was thinking we shouldn't have the inkwell effect on the comment (which maybe means the comment would also handle the tap and do a collapse?). Seems like the tap event is leaking through.

Could you clarify a bit more what you mean here?

Hmm, well if you watch my last screen recording, you can see that each time I press on the spoiler (header or body), the whole comment would display the inkwell animation (making me concerned that the comment widget was also handling the tap gesture). But I can't repro, so I guess it's not a big deal! 😊

qemu-system-x86_64_gK7ZRWIK9D.mp4

@machinaeZER0
Copy link
Collaborator

Popping in here to say that I'm personally used to spoilers being a solid block until tapped (like Sync does, apparently). I do like the title idea though, that's pretty neat! Does "test spoiler title" mean the user is able to title their spoiler, or that's just a placeholder on our end?

After some thought, I think that the solid block approach feels "simplest"/most straightforward to me, and has the extra benefit of being less likely to be misinterpreted as an external link (if we went with the spoiler turning into a title). Thoughts on that reasoning?

@machinaeZER0
Copy link
Collaborator

Hope you're both well, also :) Some great Thunder updates the last couple of months (as always!)

@micahmo
Copy link
Member

micahmo commented Dec 6, 2023

Does "test spoiler title" mean the user is able to title their spoiler

Yes exactly. Titles are part of the spoiler markdown specification. So in this example...

::: spoiler test spoiler title
spoiler body text
:::

test spoiler title is the title and is supposed to be shown. spoiler body text is the body which is supposed to be hidden. That's why I say Sync is "wrong" in not respecting the spec. Of course, having a title at all is optional. 😊

@hjiangsu
Copy link
Member Author

hjiangsu commented Dec 6, 2023

I haven't touched this feature much since the last update, but I'll work on it again soon! It seems like the general consensus here is to use a solid block to indicate spoilers.

Maybe the first step to allowing spoiler support is to implement the solid block for spoilers with the assumption that there won't be additional markdown formatting within the spoiler itself (the spoiler content will just be plain text). Once that's completed, we can move a bit further and consider ways of improving rendering custom markdown within the spoiler itself. Thoughts?

@micahmo
Copy link
Member

micahmo commented Dec 6, 2023

Maybe the first step to allowing spoiler support is to implement the solid block for spoilers with the assumption that there won't be additional markdown formatting within the spoiler itself

Yeah, that would be a great first step! Just having spoilers at all, even if the contents are (rarely) incorrectly formatted, would be a huge bonus!

@machinaeZER0
Copy link
Collaborator

That makes sense to me!

@hjiangsu hjiangsu marked this pull request as ready for review December 6, 2023 23:09
@hjiangsu
Copy link
Member Author

hjiangsu commented Dec 6, 2023

@micahmo @machinaeZER0 I've updated the original description of the PR. Feel free to take a read through it and provide any feedback!

@micahmo you can also test this out on Android to see if it's working as expected

Copy link
Member

@micahmo micahmo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey I grabbed the latest and checked out the original post you made, and things seem to be working as designed! Great job on this! I approved the PR.

However, the more I thought about this, the more I thought expanding/collapsing is the way to go (and how important showing the title is). My reasoning here is that the number 1 way I've seen spoilers used on Lemmy is not for actual spoilers, but to collapse long content.

For example, here is the programming.dev sidebar. You can see they use spoilers as more of an design/organization/layout tool than anything else. And because that's how they're rendered in the web UI and Jerboa, it seems to be a very common use case.

firefox_lFGg39vWgB.mp4

Now that sidebar looks pretty funny in Thunder, where we (a) lose the heading and (b) have huge chunks of blank space, which is exactly what the authors wanted to avoid.

qemu-system-x86_64_FU1xZFwBMd.mp4

I'm sorry I didn't think of this use case before @hjiangsu put a ton of work into changing the implementation, but I'd be curious to hear what you and @machinaeZER0 think of this and whether it's worth doing something more like the original design.

@machinaeZER0
Copy link
Collaborator

Oh weird, I would never have assumed those were handled as spoilers! Very odd implementation, there 🤔 because of this very prominent example I'm inclined to agree with going with the title/expansion route, if only for feature parity in this particular use case!

@machinaeZER0
Copy link
Collaborator

(That said, one could argue that their sidebar is "misusing" spoiler tags and that catering to their implementation doesn't necessarily follow what one might consider "best practices?" So I guess I could really go either way, honestly.)

@micahmo
Copy link
Member

micahmo commented Dec 8, 2023

Thanks for the feedback @machinaeZER0. I totally agree with you that if were developing a true spoiler UI feature from scratch, it would be very different and almost certainly block-based. However, unfortunately it seems like people have latched onto the default UI implementation on the web and are using it much more as a content organization tool. And I'm afraid if we don't follow suit, we'll be the odd ones out. But hey, that's how these things work. People realize that can use something a certain way that works and looks cool, so they do! Also our implementation can be a little more elegant (maybe the title can look more like a dropdown button, maybe the content can expand with an animation, etc.).

Here are a few more examples of instances/communities using this formatting in their sidebars (seems very common in the top communities).

https://feddit.de/
https://feddit.cl/
https://lemdro.id/
https://dormi.zone/
https://lemmy.world/c/lemmyshitpost
https://lemmy.world/c/news
https://lemmy.world/c/asklemmy
https://lemmy.world/c/nostupidquestions
https://lemmy.world/c/mildlyinfuriating
https://lemmy.world/c/linuxmemes
https://lemmy.world/c/youshouldknow
https://lemmy.world/c/memes
https://lemmy.world/c/reddit

@machinaeZER0
Copy link
Collaborator

Yeah, if the ship has sailed I think it only makes sense to fall in line 😄

@hjiangsu
Copy link
Member Author

hjiangsu commented Dec 8, 2023

I can go ahead and tweak it a bit to make it similar to how the web UI does it. I wonder though how other apps are handling this

@micahmo
Copy link
Member

micahmo commented Dec 8, 2023

I wonder though how other apps are handling this

Here's a rundown of apps from https://join-lemmy.org/apps that I could test.

  • lemmy-ui (web): expander
  • Photon (web): expander
  • Eternity (Android): not supported
  • Liftoff (Android): not supported
  • Voyager (web/Android): not supported
  • Combustible: (Android): expander
  • Summit (Android): expander
  • Jerboa (Android): expander
  • Alexandrite (web): expander
  • Boost (Android): not supported
  • Sync (Android): not supported (I know they use bock syntax in posts/comments though)

Note that my test case was to look at community sidebars, so if some of these say not supported (like Sync), it may work in post/comments.

@hjiangsu
Copy link
Member Author

Just an update on this - I finally got around to changing the implementation to use expandable content rather than spoiler blocks like before.

Here are some previews on how it looks like now, but @micahmo feel free to run it and let me know if this aligns better to how it's being used!

Collapsed Expanded
simulator_screenshot_90FF4FE7-0AAF-41E8-89A9-61BA24A79FB2 simulator_screenshot_A98915CA-E138-4675-A44B-87F78CFC5AC5
simulator_screenshot_500852DF-2BD8-4D0F-AC3A-7B9751F3A492 simulator_screenshot_B354BFFF-8C5B-464D-BC3D-5D41E9905FA2

@micahmo
Copy link
Member

micahmo commented Dec 21, 2023

Here are some previews on how it looks like now

I think this looks amazing and is even an improvement on the default implementation! I'm glad that we can have our own flavor in Thunder that feels familiar but is unique!

P.S. I noticed that it doesn't seem to work on the programming.dev instance sidebar. I'm not sure if they're using the wrong syntax, or if it's because they have nested markdown, or something else. But either way it's an edge case. This works and looks great!

@hjiangsu
Copy link
Member Author

hjiangsu commented Jan 4, 2024

I noticed that it doesn't seem to work on the programming.dev instance sidebar.

I just tried it and it seems to work. Is there a particular instance you have that I can test this on?

Regardless, I think we can merge this in first, and then fix the edge cases that pop up since they might be more difficult to track down (especially with nested markdown)

4994AAC8-00D8-4259-B258-D7A2D9C11AE0_4_5005_c 2FA98624-1BA4-4339-BD76-25A251AC1120_4_5005_c

@micahmo
Copy link
Member

micahmo commented Jan 4, 2024

I just tried it and it seems to work.

You're right, it does! Not sure what I was seeing. Maybe I was confused with a community sidebar. For example, I see this on [email protected].

image

But as you said...

Regardless, I think we can merge this in first, and then fix the edge cases that pop up

Completely agreed!

@hjiangsu
Copy link
Member Author

hjiangsu commented Jan 5, 2024

You're right, it does! Not sure what I was seeing. Maybe I was confused with a community sidebar. For example, I see this on [email protected].

Hmm, that may be a regex issue or possibly nested markdown as you mentioned. Regardless, I'll merge this in first and then look into this a bit more!

@hjiangsu hjiangsu merged commit 858c531 into develop Jan 5, 2024
@hjiangsu hjiangsu deleted the feature/markdown-spoiler branch January 5, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants