From 97ae1c4058c09731033847226942342fdee30be8 Mon Sep 17 00:00:00 2001 From: Botond Hende Date: Sat, 7 Sep 2024 23:42:26 +0200 Subject: quote to handle source --- quote.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'quote.py') 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'

"

{self.render_children(element)}

"

' + def render_quote_element(self, element: QuoteElement): + source = f'

-- {element.source}

' if element.source is not None else '' + return f'

"

{element.quote}

"

{source}
' Quote = MarkoExtension( -- cgit v1.2.3-70-g09d2