diff --git a/Dockerfile b/Dockerfile index 0546032..adb2633 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,22 @@ # -------- Stage 1: Build the documentation using mkdocs -------- FROM python:3.13-slim AS builder +# add pandoc to image +COPY --from=pandoc/minimal:3 /usr/local/bin/pandoc /usr/local/bin/pandoc + +RUN chmod +x /usr/local/bin/pandoc + WORKDIR /build # Install dependencies COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt +COPY mkdocs/ mkdocs/ +COPY pandoc/filters pandoc/filters COPY user/ user/ COPY admin/ admin/ -RUN ls RUN cd user && mkdocs build --clean && cd .. RUN cd admin && mkdocs build --clean && cd .. diff --git a/admin/docs/generation-documents.md b/admin/docs/generation-documents.md index 056d585..305746e 100644 --- a/admin/docs/generation-documents.md +++ b/admin/docs/generation-documents.md @@ -49,7 +49,7 @@ Le document est préparé de manière habituelle: le texte y est écrit, le logo Le travail de préparation consiste à préciser les endroits où ces informations doivent être insérées: des champs spécifiques. -::: .note +::: {.note} Le fonctionnement de la génération de document est assez semblable au "publi-postage": des champs sont définis dans le document, et le logiciel de traitement de texte vient les remplacer par ceux provenant d'une base de donnée. diff --git a/admin/mkdocs.yml b/admin/mkdocs.yml index a0e1670..9dff5da 100644 --- a/admin/mkdocs.yml +++ b/admin/mkdocs.yml @@ -12,6 +12,8 @@ theme: nav: - Accueil: index.md - Génération de document: generation-documents.md +hooks: + - ../mkdocs/hooks/pandoc-to-mkdocs.py markdown_extensions: - markdown_include.include # code layout diff --git a/mkdocs/hooks/pandoc-to-mkdocs.py b/mkdocs/hooks/pandoc-to-mkdocs.py new file mode 100644 index 0000000..352cb97 --- /dev/null +++ b/mkdocs/hooks/pandoc-to-mkdocs.py @@ -0,0 +1,29 @@ +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 \ No newline at end of file diff --git a/pandoc/filters/admonitionTransformer.lua b/pandoc/filters/admonitionTransformer.lua new file mode 100644 index 0000000..3ea5309 --- /dev/null +++ b/pandoc/filters/admonitionTransformer.lua @@ -0,0 +1,27 @@ +-- admonition.lua +-- Filtre Pandoc : transforme les divs en admonitions type "!!! note" + +function Div(div) + if div.classes ~= nil and #div.classes > 0 then + local class = div.classes[1] + -- Génère le préfixe admonition + local admonition_header = pandoc.Plain{pandoc.Str("!!! " .. class)} + local contents = {} + + -- Pour chaque bloc de contenu, ajoute une indentation de 4 espaces à chaque ligne + for _, blk in ipairs(div.content) do + local s = pandoc.write(pandoc.Pandoc({blk}), "markdown") + -- Ajoute une indentation de 4 espaces sur chaque ligne non vide + s = s:gsub("([^\n]+)", " %1") + table.insert(contents, pandoc.RawBlock("markdown", s)) + end + + -- Construit la nouvelle sequence de blocs : en-tête + contenus + local blocks = {admonition_header} + for _, blk in ipairs(contents) do + table.insert(blocks, blk) + end + + return blocks + end +end \ No newline at end of file diff --git a/pandoc/filters/admonitionTransformer/from.md b/pandoc/filters/admonitionTransformer/from.md new file mode 100644 index 0000000..72db921 --- /dev/null +++ b/pandoc/filters/admonitionTransformer/from.md @@ -0,0 +1,11 @@ + +::: { .note } +Ceci est une note +::: + + +::: { .warning } + +Ceci est un warning + +::: \ No newline at end of file diff --git a/user/mkdocs.yml b/user/mkdocs.yml index ad16803..8db2cd3 100644 --- a/user/mkdocs.yml +++ b/user/mkdocs.yml @@ -38,6 +38,8 @@ nav: - Exports liés aux parcours: exports_accompanying_period.md - Exports liés aux actions sociales: exports_accompanying_period_work.md - Exports liés aux évaluations: exports_accompanying_period_work_evaluation.md +hooks: + - ../mkdocs/hooks/pandoc-to-mkdocs.py markdown_extensions: - markdown_include.include # code layout @@ -66,4 +68,4 @@ markdown_extensions: - pymdownx.caret - pymdownx.keys - pymdownx.mark - - pymdownx.tilde \ No newline at end of file + - pymdownx.tilde