summaryrefslogtreecommitdiff
path: root/fakehtmltag.py
diff options
context:
space:
mode:
authorBotond Hende <nettingman@gmail.com>2024-09-22 14:29:14 +0200
committerBotond Hende <nettingman@gmail.com>2024-09-22 14:29:14 +0200
commit57ad1a02f119e81d44141c7f4960574132f392c4 (patch)
treeddad7ab62637aa2d1ba58d07487e1be0dd49058f /fakehtmltag.py
parent97ae1c4058c09731033847226942342fdee30be8 (diff)
fake html tag
Diffstat (limited to 'fakehtmltag.py')
-rw-r--r--fakehtmltag.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/fakehtmltag.py b/fakehtmltag.py
new file mode 100644
index 0000000..4a7dfa4
--- /dev/null
+++ b/fakehtmltag.py
@@ -0,0 +1,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">&lt</span><span class="yellow">{element.tag}</span><span class="cyan">&gt</span></span>{self.render_children(element)}<span class="nobr"><span class="cyan">&lt/</span><span class="yellow">{element.tag}</span><span class="cyan">&gt</span></span>'
+
+
+FakeHtml = MarkoExtension(
+ elements=[FakeHtmlElement],
+ renderer_mixins=[FakeHtmlRenderer]
+)