fix(export): clear template tables in _clear_body — חתימות לסוף, א–ד ללא נתונים (#205)
תיקוני-תבנית DOCX (WS5 ת1–ת3): הטמפלט decision_template.docx מכיל 3 טבלאות- דוגמה (כותרת מוסדית / הרכב / חתימות). _clear_body הסיר רק <w:p> והשאיר את הטבלאות. כתוצאה: - ת3 (שורש): טבלת-החתימות שרדה במיקום-הטמפלט (למעלה, צמוד לטבלת-הכותרת/בלוק-ד), וכל תוכן-ההחלטה נדחף אחריה. החתימות הופיעו בראש המסמך במקום בסוף. - ת1: טבלאות הכותרת/הרכב הזריקו נתוני בלוק-א–ד שלא חולצו מהפרוטוקול. התיקון בשכבת-הרינדור (G1 — לתקן במקור, לא לשכפל סימפטום): _clear_body מסיר כעת את כל גוף-המסמך (פסקאות, טבלאות, ו-bookmarks יתומים) ומשאיר רק sectPr. ההחלטה משוחזרת כולה מ-decision_blocks (INV-EX1) — החתימות מגיעות מ-block-yod-bet שמרונדר אחרון בסדר-הבלוקים, ולכן טבלאות-הדוגמה הן פיגום מיושן שצריך להימחק. ת2 כבר תקין: block-dalet מרנדר רק את הכותרת "החלטה" (Heading 1, מתעלם מתוכן- ה-DB) — הוסף test מפורש לנעילה. תוקן גם ב-analysis_docx_exporter._clear_body (אותו באג, סימטריה G2). Tests: 4 regression חדשים + 27 docx-tests עוברים. Invariants: INV-EX1 (DOCX נתון-נגזר מ-decision_blocks, ללא דליפת תוכן-טמפלט) · G1 (תיקון-במקור) · G2 (סימטריה בין שני ה-exporters) · G11/block-schema (block-ד = כותרת בלבד, block-יב = חתימות בסוף). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -182,16 +182,21 @@ def _add_runs_with_inline_bold(paragraph: Paragraph, text: str) -> None:
|
||||
|
||||
|
||||
def _clear_body(doc: DocumentT) -> None:
|
||||
"""Remove every paragraph currently in the document body.
|
||||
"""Remove ALL body content (paragraphs, tables, stray bookmarks),
|
||||
keeping only sectPr.
|
||||
|
||||
The template ships with example paragraphs ("רקע", "דיון והכרעה"…)
|
||||
that we don't want in the output. Section properties (sectPr) are
|
||||
kept so page size / margins / RTL / footer remain intact.
|
||||
The template ships with example paragraphs ("רקע", "דיון והכרעה"…) *and
|
||||
three sample tables* (header / panel / signatures). Removing only ``w:p``
|
||||
left the tables behind — including the signatures table, which then floated
|
||||
to the top against the header table. Mirror the decision exporter's
|
||||
``_clear_body`` (G2 symmetry): drop everything except sectPr, which carries
|
||||
page setup including bidi.
|
||||
"""
|
||||
body = doc.element.body
|
||||
for p in list(body.findall(qn("w:p"))):
|
||||
body.remove(p)
|
||||
# Leave sectPr alone — it carries page setup including bidi.
|
||||
sectPr_tag = qn("w:sectPr")
|
||||
for child in list(body):
|
||||
if child.tag != sectPr_tag:
|
||||
body.remove(child)
|
||||
|
||||
|
||||
def _add_paragraph(doc: DocumentT, text: str, style: str) -> Paragraph:
|
||||
|
||||
@@ -192,14 +192,29 @@ def _apply_list_numbering(paragraph, num_id: int) -> None:
|
||||
|
||||
|
||||
def _clear_body(doc) -> None:
|
||||
"""Remove all paragraphs in the document body while keeping sectPr.
|
||||
"""Remove ALL body content (paragraphs, tables, stray bookmarks) while
|
||||
keeping only sectPr.
|
||||
|
||||
The template ships with sample paragraphs we don't want. Section
|
||||
properties (page size, margins, bidi) stay intact.
|
||||
The template ships with sample paragraphs *and three sample tables*
|
||||
(institutional header, panel, and a **signatures** table at the end —
|
||||
"ניתנה פה אחד" + יו"ר/מזכירה). Removing only ``w:p`` left those tables
|
||||
behind: the leftover header/panel tables injected block-א–ד data that was
|
||||
never extracted from the protocol (violates the empty-unless-extracted
|
||||
rule), and the leftover signatures table collapsed up against the header
|
||||
table at the **top** of the document (the chair-reported bug: חתימות צמודות
|
||||
לבלוק-ד במקום בסוף). The decision is a derived artifact rebuilt purely from
|
||||
``decision_blocks`` (INV-EX1) — signatures come from block-yod-bet, rendered
|
||||
last in block order — so the template's sample tables are stale scaffolding
|
||||
and must go. Section properties (page size, margins, bidi) stay intact.
|
||||
"""
|
||||
body = doc.element.body
|
||||
for p in list(body.findall(qn("w:p"))):
|
||||
body.remove(p)
|
||||
sectPr_tag = qn("w:sectPr")
|
||||
for child in list(body):
|
||||
# Keep section properties (page setup / bidi). Drop everything else:
|
||||
# sample paragraphs (w:p), sample tables (w:tbl), and any stray
|
||||
# bookmark markers the template left dangling between them.
|
||||
if child.tag != sectPr_tag:
|
||||
body.remove(child)
|
||||
|
||||
|
||||
# ── Bookmark helpers ──────────────────────────────────────────────
|
||||
|
||||
Reference in New Issue
Block a user