Improve style

This commit is contained in:
2026-05-02 19:13:08 +02:00
parent c93d26d696
commit 690deff6e5
2 changed files with 34 additions and 6 deletions

View File

@@ -25,6 +25,7 @@ def default_content_root() -> Path:
CONTENT_ROOT = Path(os.getenv("PROGRAM_CONTENT_ROOT", default_content_root())).resolve()
LESSON_BACKGROUND = "#f5f7fb"
GRADE_ALIASES = {
"CM1": "cm1",
@@ -134,6 +135,32 @@ def render_svg_section(path: Path, section_index: int) -> str:
raise IndexError("Section introuvable")
x, y, width, height = sections[section_index]["view_box"]
text = path.read_text(encoding="utf-8", errors="ignore")
first_group_index = text.find("<g ")
if first_group_index > -1:
before_groups = text[:first_group_index]
after_groups = text[first_group_index:]
before_groups = re.sub(
r"\.bg\s*\{[^}]*\}",
f".bg {{ fill: {LESSON_BACKGROUND}; }}",
before_groups,
count=1,
)
before_groups = re.sub(
r"\.panel\s*\{[^}]*\}",
(
".panel { fill: #ffffff; stroke: #d5e0dc; stroke-width: 3; "
"filter: drop-shadow(0 10px 24px rgba(22, 42, 45, 0.08)); }"
),
before_groups,
count=1,
)
before_groups = re.sub(
r'(<rect\b(?=[^>]*class="panel")(?=[^>]*/>)[^>]*)/>',
rf'\1 style="fill:{LESSON_BACKGROUND};stroke:none;filter:none"/>',
before_groups,
count=1,
)
text = before_groups + after_groups
text = re.sub(r'\swidth="[^"]+"', f' width="{int(width)}"', text, count=1)
text = re.sub(r'\sheight="[^"]+"', f' height="{int(height)}"', text, count=1)
text = re.sub(