-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
31 lines (23 loc) · 1.06 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
def define_env(env):
"Hook function"
@env.macro
def basthon(exo: str, hauteur: int) -> str:
"Renvoie du HTML pour embarquer un fichier `exo` dans Basthon"
return f"""<iframe src="https://console.basthon.fr/?from={env.variables.site_url}{env.variables.page.url}../{exo}" width=100% height={hauteur}></iframe>
[Lien dans une autre page](https://console.basthon.fr/?from={env.variables.site_url}{env.variables.page.url}../{exo})
"""
@env.macro
def script(lang: str, nom: str) -> str:
"Renvoie le script dans une balise bloc avec langage spécifié"
return f"""```{lang}
--8<--- "docs/""" + os.path.dirname(env.variables.page.url.rstrip('/')) + f"""/{nom}"
```"""
@env.macro
def py(nom: str) -> str:
"macro python rapide"
return script('python', "scripts/" + nom + ".py")
@env.macro
def html_fig(num: int) -> str:
"Renvoie le code HTML de la figure n° `num`"
return f'--8<-- "docs/' + os.path.dirname(env.variables.page.url.rstrip('/')) + f'/figures/fig_{num}.html"'