From 0f2a22208906cb2f7aeaf01bccaeb9c58fb83ae3 Mon Sep 17 00:00:00 2001 From: Botond Hende Date: Sun, 22 Sep 2024 19:50:55 +0200 Subject: spoiler renderer --- spoiler.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 spoiler.py 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
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'' + + +Spoiler = MarkoExtension( + elements=[SpoilerElement], + renderer_mixins=[SpoilerRenderer] +) -- cgit v1.2.3-70-g09d2