Update `codebox` macro
[GitHub/WoltLab/woltlab.github.io.git] / main.py
1 def define_env(env):
2 @env.macro
3 def codebox(title = None, language = "", filepath = None, contents = ""):
4 if title is not None:
5 if filepath is not None:
6 return f"""
7 <div class="titledCodeBox">
8 <div class="codeBoxTitle"><code>{title}</code></div>
9 ```{language}
10 --8<-- "{filepath}"
11 ```
12 </div>
13 """
14 else:
15 return f"""
16 <div class="titledCodeBox">
17 <div class="codeBoxTitle"><code>{title}</code></div>
18 ```{language}
19 {contents}
20 ```
21 </div>
22 """
23 else:
24 if filepath is not None:
25 return f"""
26 ```{language}
27 --8<-- "{filepath}"
28 ```
29 """
30 else:
31 return f"""
32 ```{language}
33 {contents}
34 ```
35 """