summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBotond Hende <nettingman@gmail.com>2024-09-07 23:42:26 +0200
committerBotond Hende <nettingman@gmail.com>2024-09-07 23:42:26 +0200
commit97ae1c4058c09731033847226942342fdee30be8 (patch)
tree26eecb341786aa5c5778975fc637d4d30adad8c9
parent9ceea408679913000039013f3a1ddfb695880e6a (diff)
quote to handle source
-rw-r--r--quote.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/quote.py b/quote.py
index 06897d2..56ae0bc 100644
--- a/quote.py
+++ b/quote.py
@@ -4,19 +4,27 @@ 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 QuoteElement(inline.InlineElement):
- pattern = '"""(.+)"""'
+ pattern = '"""([^"]*)(?:""([^"]*))?"""'
parse_children = True
+ def __init__(self, match):
+ self.quote = match.group(1)
+ self.source = match.group(2) if match.group(2) is not None and not match.group(2).isspace() else None
+
+
class QuoteRenderer:
- def render_quote_element(self, element):
- return f'<div class="quote"><p>"</p><p>{self.render_children(element)}</p><p>"</p></div>'
+ def render_quote_element(self, element: QuoteElement):
+ source = f'<p class="quote-source">-- {element.source}</p>' if element.source is not None else ''
+ return f'<div class="quote"><div class="quote-main"><p>"</p><p>{element.quote}</p><p>"</p></div>{source}</div>'
Quote = MarkoExtension(