diff options
-rw-r--r-- | headinginjector.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/headinginjector.py b/headinginjector.py new file mode 100644 index 0000000..50ef606 --- /dev/null +++ b/headinginjector.py @@ -0,0 +1,18 @@ +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"<h{element.level}>{HeadingRenderer.PREFIX}{self.render_children(element)}</h{element.level}>\n" + + return HeadingRenderer + + +def get_heading_injector(prefix: str): + return MarkoExtension( + renderer_mixins=[__create_heading_renderer(prefix)] + ) |