summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBotond Hende <nettingman@gmail.com>2024-07-14 23:36:20 +0200
committerBotond Hende <nettingman@gmail.com>2024-07-15 23:34:41 +0200
commit3295abdee147801c86b56ec77643dcc416f8ed3e (patch)
tree8f2aebf74c3a76cb2f78e38d222d940ed8e77e63
parent3d94849523db563ae1a835987c45d135a518d77c (diff)
heading injector module
-rw-r--r--headinginjector.py18
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)]
+ )