manuals/mkdocs/hooks/pandoc-to-mkdocs.py
Julien Fastré 7a021838f1
Some checks failed
continuous-integration/drone/push Build is failing
Build and Push MkDocs Docker Image / build-and-push (push) Successful in 2m18s
Transforme les divs de pandoc en admonition
2025-06-30 23:36:44 +02:00

29 lines
1.1 KiB
Python

import subprocess
import os
def on_page_markdown(markdown: str, page, config, files) -> str | None:
# Récupère le dossier où se trouve mkdocs.yaml
base_dir = os.path.dirname(config.config_file_path)
# Construit le chemin absolu du filtre lua relatif à mkdocs.yaml
lua_filter_path = os.path.normpath(os.path.join(base_dir, '../pandoc/filters/admonitionTransformer.lua'))
# Prépare la commande avec le chemin correct pour le filtre
cmd = [
"pandoc",
f"--lua-filter={lua_filter_path}",
"--to", "markdown"
]
try:
# Appelle le script bash/commande via subprocess, en passant le markdown via stdin
result = subprocess.run(
cmd,
input=markdown.encode('utf-8'),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True
)
# Retourne la sortie standard (stdout) décodée
return result.stdout.decode('utf-8')
except subprocess.CalledProcessError as e:
print("Erreur lors de l'exécution du script bash :", e.stderr.decode('utf-8'))
return None