blob: 4a7dfa442d7bb2e6df65f33a5adfb55c625b5af3 (
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
|
"""
Encapsulates text in a fake html tag that is colored (class="cyan" and class="yellow") and has a "nobr" class for no wrapping.
These all can be styled in css.
Usage:
{{my_fake_html_tag}}content{{}}
"""
from marko import inline
from marko.helpers import MarkoExtension
class FakeHtmlElement(inline.InlineElement):
pattern = '{{(.*)}}(.*){{}}'
parse_children = True
parse_group = 2
def __init__(self, match):
self.tag = match.group(1)
self.content = match.group(2)
class FakeHtmlRenderer:
def render_fake_html_element(self, element: FakeHtmlElement):
return f'<span class="nobr"><span class="cyan"><</span><span class="yellow">{element.tag}</span><span class="cyan">></span></span>{self.render_children(element)}<span class="nobr"><span class="cyan"></</span><span class="yellow">{element.tag}</span><span class="cyan">></span></span>'
FakeHtml = MarkoExtension(
elements=[FakeHtmlElement],
renderer_mixins=[FakeHtmlRenderer]
)
|