-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
26 lines (20 loc) · 809 Bytes
/
main.py
File metadata and controls
26 lines (20 loc) · 809 Bytes
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
import re
import os
def define_env(env):
@env.macro
def render_glossary(filepath="includes/glossaire.md"):
if not os.path.exists(filepath):
return f"**Error**: Glossary file not found at {filepath}"
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read()
# Regex to find: *[Term]: Definition
# Group 1: Term, Group 2: Definition
pattern = r"\*\[(.*?)\]:\s*(.*)"
matches = re.findall(pattern, content)
if not matches:
return "_No definitions found in glossary._"
# Format the output as a Markdown table
output = "| Terme | Définition |\n| :--- | :--- |\n"
for term, definition in matches:
output += f"| **{term}** | {definition} |\n"
return output