blob: 0ec02dcf49e97b17aa998e1d4f236dc7d8bf8c1e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
"""
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 QuoteElement(inline.InlineElement):
pattern = '"""([^"]*)(?:""([^"]*))?"""'
parse_children = True
def __init__(self, match):
self.children = 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: 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>{self.render_children(element)}</p><p>"</p></div>{source}</div>'
Quote = MarkoExtension(
elements=[QuoteElement],
renderer_mixins=[QuoteRenderer]
)
|