""" Prefixes headers with the specified string. Usage: MyExtension = get_heading_injector(prefix) """ import marko.block from marko.helpers import MarkoExtension def __create_heading_renderer(prefix: str): class HeadingRenderer: PREFIX = prefix def render_heading(self, element: marko.block.Heading): return f"{HeadingRenderer.PREFIX}{self.render_children(element)}\n" return HeadingRenderer def get_heading_injector(prefix: str): return MarkoExtension( renderer_mixins=[__create_heading_renderer(prefix)] )