All checks were successful
Build & Deploy / build-and-deploy (push) Successful in 6s
Documents the rules and decisions behind building DOCX files from דפנה's
decision template (טיוטת החלטה.dotx). The implementation lives in
mcp-server/src/legal_mcp/services/analysis_docx_exporter.py; this skill
captures the "why" so future improvements don't need to rediscover it.
Contents:
SKILL.md 5 critical rules, style mapping table,
export flow, line classification,
dash policy, placeholder handling,
troubleshooting, future TODOs
references/dotx-to-docx.md why python-docx can't open .dotx +
the conversion recipe
references/rtl-runs.md why <w:rtl/> is required on every run
(otherwise Hebrew falls back to
Times New Roman)
references/style-mapping.md XML dump of every template style,
with the Title-via-theme gotcha
references/line-classification.md the 7 regex categories in
_classify_line() with real examples
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2.3 KiB
2.3 KiB
המרת .dotx → .docx עבור python-docx
למה
python-docx לא יודע לפתוח קובצי Word Template (.dotx). ניסיון לפתיחה
זורק:
ValueError: file 'X.dotx' is not a Word file, content type is
'application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml'
כי main document part של .dotx מסומן כ-template, לא כ-document.
הפתרון — המרה חד-פעמית
קובץ .dotx הוא ZIP שכולל את אותם parts כמו .docx + word/glossary/
(building blocks). להמרה:
- פתח את ה-ZIP.
- הסר את כל ה-parts תחת
word/glossary/. - תקן
[Content_Types].xml:- החלף
template.main+xmlב-document.main+xml - הסר
<Override>entries שמצביעים ל-/word/glossary/...
- החלף
- תקן
word/_rels/document.xml.rels:- הסר את ה-
<Relationship>עםType=".../relationships/glossaryDocument"
- הסר את ה-
- שמור מחדש כ-ZIP עם סיומת
.docx.
הסקריפט
scripts/convert_decision_template.py
(בשורש הפרויקט) עושה את זה. הרץ אותו:
- פעם אחת אחרי clone של הפרויקט (אם
skills/docx/decision_template.docxלא קיים). - בכל פעם שדפנה מעדכנת את
data/training/טיוטת החלטה.dotx.
python scripts/convert_decision_template.py
# → skills/docx/decision_template.docx
הסקריפט כולל verification שבודק שהקובץ שנוצר נטען נקי ב-python-docx ושהסגנונות הקריטיים (Normal, Heading 2, Quote, List Paragraph, Title) נמצאים בו.
למה לא docxtpl?
docxtpl מיועד ל-placeholder substitution סגנון Jinja2
({{ variable }}). הטמפלט שלנו לא מכיל placeholders — אנחנו מרכיבים
תוכן דינמי. python-docx על טמפלט .docx נקי מספיק לגמרי.
הימנע מ-
- אל תנסה להוריד את ה-glossary רק מ-
[Content_Types].xmlבלי להסיר את ה-<Relationship>שמפנה אליו → תקבל dangling reference. - אל תנסה להשתמש ב-
.dotxישירות דרךzipfile+ לבנות Document ידנית — חוסך 10 שורות אבל מאבד את כל ה-robustness של python-docx.