Add macro for titled code boxes
authorMatthias Schmidt <gravatronics@live.com>
Fri, 23 Apr 2021 09:05:57 +0000 (11:05 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Fri, 23 Apr 2021 09:05:57 +0000 (11:05 +0200)
.gitignore
main.py [new file with mode: 0644]

index a2414a411d11cccfdf65278ebbdabb2b18a559de..c07ca819e1e3a7417df3afbe9bb3a4ad6e3c17cc 100644 (file)
@@ -60,3 +60,6 @@ nbactions.xml
 
 # Node.js
 extra/node_modules
+
+# Python
+__pycache__/
diff --git a/main.py b/main.py
new file mode 100644 (file)
index 0000000..7867e5a
--- /dev/null
+++ b/main.py
@@ -0,0 +1,18 @@
+def define_env(env):
+    @env.macro
+    def codebox(language, filepath, title = ""):
+        if title is not "":
+            return f"""
+<div class="titledCodeBox">
+    <div class="codeBoxTitle"><code>{title}</code></div>
+    ```{language}
+    --8<-- "{filepath}"
+    ```
+</div>
+"""
+        else:
+            return f"""
+```{language}
+--8<-- "{filepath}"
+```
+"""