summaryrefslogtreecommitdiff
path: root/headinginjector.py
blob: 50ef606d3580a75501369fb6085861893e7e8e66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)]
    )