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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/markdown2.py
Expand Up @@ -2765,6 +2765,19 @@ def run(self, text):
return self.fenced_code_block_re.sub(self.sub, text)


class LemmySpoiler(Extra):
name = 'lemmy-spoiler'
order = (), (Stage.ITALIC_AND_BOLD,)

_lemmy_spoiler_re = re.compile(r":{3} spoiler\s+?(\S.+?\n)(.+?)\n:{3}", re.S)

def run(self, text):
return self._lemmy_spoiler_re.sub(r"<details><summary>\1</summary>\2</details>", text)

def test(self, text):
return '::: spoiler' in text


class LinkPatterns(Extra):
'''
Auto-link given regex patterns in text (e.g. bug number
Expand Down Expand Up @@ -3328,6 +3341,7 @@ def test(self, text):
Breaks.register()
CodeFriendly.register()
FencedCodeBlocks.register()
LemmySpoiler.register()
LinkPatterns.register()
MarkdownInHTML.register()
MiddleWordEm.register()
Expand Down
6 changes: 6 additions & 0 deletions test/tm-cases/lemmy-spoiler.html
@@ -0,0 +1,6 @@
<p><details><summary>this part is visible
</summary>but this part will be hidden</details></p>

<p><details><summary>this part is visible
</summary>but this part
and this part are hidden</details></p>
1 change: 1 addition & 0 deletions test/tm-cases/lemmy-spoiler.opts
@@ -0,0 +1 @@
{"extras": ["lemmy-spoiler"]}
1 change: 1 addition & 0 deletions test/tm-cases/lemmy-spoiler.tags
@@ -0,0 +1 @@
extras lemmy-spoiler
8 changes: 8 additions & 0 deletions test/tm-cases/lemmy-spoiler.text
@@ -0,0 +1,8 @@
::: spoiler this part is visible
but this part will be hidden
:::

::: spoiler this part is visible
but this part
and this part are hidden
:::