summaryrefslogtreecommitdiff
path: root/spoiler.py
diff options
context:
space:
mode:
Diffstat (limited to 'spoiler.py')
-rw-r--r--spoiler.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/spoiler.py b/spoiler.py
new file mode 100644
index 0000000..ee15dfd
--- /dev/null
+++ b/spoiler.py
@@ -0,0 +1,35 @@
+"""
+Encapsulates text in a <div> html tag with the class "quote" and between two paragraphs which contain a quote (").
+These all can be styled in css.
+
+Usage (without the backslashes):
+\"""my quote\"""
+or
+\"""my quote "" source \"""
+"""
+from marko import inline
+from marko.helpers import MarkoExtension
+
+
+class SpoilerElement(inline.InlineElement):
+ pattern = '\\|\\|(.*)\\|\\|(.*)\\|\\|'
+ parse_children = True
+ parse_group = 2
+ priority = 7
+
+ def __init__(self, match):
+ self.id = match.group(1)
+ self.children = match.group(2)
+
+
+
+class SpoilerRenderer:
+ def render_spoiler_element(self, element: SpoilerElement):
+ content = self.render_children(element)
+ return f'<span><input type="checkbox" class="spoiler" id="{element.id}"><label class="spoiler-on" for="{element.id}"><span>{"▉" * len(content)}</span></label><label class="spoiler-off" for="{element.id}"><span>{content}</span></label></span>'
+
+
+Spoiler = MarkoExtension(
+ elements=[SpoilerElement],
+ renderer_mixins=[SpoilerRenderer]
+)