""" 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'<{element.tag}>{self.render_children(element)}</{element.tag}>' FakeHtml = MarkoExtension( elements=[FakeHtmlElement], renderer_mixins=[FakeHtmlRenderer] )