14
246
Fork
You've already forked pyfedi
75

Spoiler Block Improvements #1646

Merged
rimu merged 4 commits from wjs018/pyfedi:better_spoiler_blocks into main 2026年02月14日 22:07:01 +01:00
Collaborator
Copy link

This addresses #1365 and #1612. I also addressed the most common point of failure I see when people don't format spoiler blocks correctly; what I call the naked spoiler block. Basically, they format everything correctly, but don't include summary text:

::: spoiler
This is a naked spoiler block.
:::

Lemmy just renders this as normal markdown and not as a spoiler block. I think if you write out a fully formatted spoiler block, but just leave it naked like this, the intent is clear enough that the software can help you along. So, this PR preprocesses the markdown and tweaks the formatting like so:

::: spoiler Spoiler
This is no longer a naked spoiler block.
:::

This should render nicer with actual text in the <summary> tag.

Overall, here is what this PR does:

  • Adds a function to handle naked spoiler blocks (prior to markdown2 parsing)
  • Adds a function to insert an empty line after a spoiler opening line, solving #1612 (after naked spoilers, but before markdown2)
  • Adds a function to substitute <details> and <summary> blocks for the spoiler block markdown (after markdown2)
    • Note that this only happens if there are an equal number of spoiler block openings and closings. That we can be sure that we aren't substituting in html tags that don't have a corresponding opening/closing tag.
    • If the number of openings and closings are not equal, we fall back to the way spoiler blocks were handled prior to this PR.
  • Adds new tests for markdown_to_html for the above points.
  • Adds styling for spoiler blocks. Once nested spoiler blocks are possible, I felt it was necessary to visually indicate when one spoiler block is enclosed within another.
This addresses #1365 and #1612. I also addressed the most common point of failure I see when people don't format spoiler blocks correctly; what I call the naked spoiler block. Basically, they format everything correctly, but don't include summary text: ```md ::: spoiler This is a naked spoiler block. ::: ``` Lemmy just renders this as normal markdown and not as a spoiler block. I think if you write out a fully formatted spoiler block, but just leave it naked like this, the intent is clear enough that the software can help you along. So, this PR preprocesses the markdown and tweaks the formatting like so: ```md ::: spoiler Spoiler This is no longer a naked spoiler block. ::: ``` This should render nicer with actual text in the `<summary>` tag. Overall, here is what this PR does: - Adds a function to handle naked spoiler blocks (prior to markdown2 parsing) - Adds a function to insert an empty line after a spoiler opening line, solving #1612 (after naked spoilers, but before markdown2) - Adds a function to substitute `<details>` and `<summary>` blocks for the spoiler block markdown (after markdown2) - Note that this only happens if there are an equal number of spoiler block openings and closings. That we can be sure that we aren't substituting in html tags that don't have a corresponding opening/closing tag. - If the number of openings and closings are not equal, we fall back to the way spoiler blocks were handled prior to this PR. - Adds new tests for `markdown_to_html` for the above points. - Adds styling for spoiler blocks. Once nested spoiler blocks are possible, I felt it was necessary to visually indicate when one spoiler block is enclosed within another.
Sign in to join this conversation.
No reviewers
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
rimu/pyfedi!1646
Reference in a new issue
rimu/pyfedi
No description provided.
Delete branch "wjs018/pyfedi:better_spoiler_blocks"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?