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.