Transforme les divs de pandoc en admonition
This commit is contained in:
parent
95dadee345
commit
7a021838f1
@ -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 ..
|
||||
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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
|
||||
|
29
mkdocs/hooks/pandoc-to-mkdocs.py
Normal file
29
mkdocs/hooks/pandoc-to-mkdocs.py
Normal file
@ -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
|
27
pandoc/filters/admonitionTransformer.lua
Normal file
27
pandoc/filters/admonitionTransformer.lua
Normal file
@ -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
|
11
pandoc/filters/admonitionTransformer/from.md
Normal file
11
pandoc/filters/admonitionTransformer/from.md
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
::: { .note }
|
||||
Ceci est une note
|
||||
:::
|
||||
|
||||
|
||||
::: { .warning }
|
||||
|
||||
Ceci est un warning
|
||||
|
||||
:::
|
@ -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
|
||||
- pymdownx.tilde
|
||||
|
Loading…
x
Reference in New Issue
Block a user