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

WIP: Add extra for Lemmy spoiler format #574

Closed
wants to merge 1 commit into from

Conversation

freamon
Copy link

@freamon freamon commented Apr 2, 2024

Hello,

How would you feel about adding an extra for Lemmy's spoiler format? Lemmy is a Reddit clone that uses ActivityPub (it's a Fediverse app like Mastodon (which itself aims to be an alternative to Twitter)). Why Lemmy decided to use their own format for spoilers is a mystery.

The goal would be to use it with PieFed, which gets most of its content federated in from Lemmy, but recreates the HTML using Markdown2 rather than risk using the HTML they provide. (it also uses Markdown2 for locally created content too, of course)

The PieFed dev suspects that Lemmy is too niche for you to want to add it to your codebase, and we'll have to clobber the generated HTML separately, but it'll be neater if we don't have to.

Many thanks.

@nicholasserra
Copy link
Collaborator

Hello! Thanks for the PR. Seems like an okay thing to add. We have some weird extras. You tested this implementation end to end with whatever external processor this is using?

@freamon
Copy link
Author

freamon commented Apr 8, 2024

Hi. Yes. I just did some paranoid re-testing, and it looks okay.
Currently, the piefed code is just doing:

raw_html = markdown2.markdown(markdown_text, safe_mode=True, extras={'middle-word-em': False, 'tables': True, 'fenced-code-blocks': True, 'strike': True})
re_spoiler = re.compile(r':{3} spoiler\s+?(\S.+?\n)(.+?)\n:{3}', re.S)
raw_html = re_spoiler.sub(r'<details><summary>\1</summary>\2</details>', raw_html)

viewable here

This is the same regex as in the PR, and it produces the expected result on piefed.social (this was a post sent in remotely and commented on locally).

@freamon freamon changed the title Add extra for Lemmy spoiler format WIP: Add extra for Lemmy spoiler format Apr 9, 2024
@freamon
Copy link
Author

freamon commented Apr 9, 2024

Actually, further testing has revealed that this doesn't work if there's paragraphs of text inside the spoiler. I need to do more work on this to get it right, so please don't merge it just yet. You may prefer to close this, and I'll submit another PR if I can solve the problem. Thanks.

@nicholasserra
Copy link
Collaborator

Thanks for the extra testing. Will close for now.

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.

None yet

2 participants