From f4306f130e2ca9352f7d9db3318cb7eb100fe831 Mon Sep 17 00:00:00 2001 From: DokoGen Date: Mon, 3 Aug 2026 10:12:09 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D1=8F?= =?UTF-8?q?=D1=82=D1=8C=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D1=8B=D0=B5=20=D0=B1=D0=B5=D0=B7=20=D0=BF=D1=80=D0=B5=D1=84?= =?UTF-8?q?=D0=B8=D0=BA=D1=81=D0=B0=20item.=20=D0=B2=D0=BD=D1=83=D1=82?= =?UTF-8?q?=D1=80=D0=B8=20=D1=86=D0=B8=D0=BA=D0=BB=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Word разбивает на run'ы не только маркеры циклов, но и переменные ({{name}}, {{number}}, {{pd_list}} и т.д.). Нормализация теперь склеивает все параграфы с {{...}}, а размножение цикла подставляет и {{item.field}}, и {{field}} (шаблон '0. Акт обследования.docx') --- dokogen/generator.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/dokogen/generator.py b/dokogen/generator.py index f35be88..557977c 100644 --- a/dokogen/generator.py +++ b/dokogen/generator.py @@ -89,8 +89,8 @@ def _normalize_loop_markers(doc_xml: str) -> str: texts.append(t.text or '') full = ''.join(texts) - # Интересуют только параграфы с маркерами циклов ИЛИ переменными цикла - if 'loop:' not in full and 'loop_end' not in full and '{{item.' not in full: + # Интересуют параграфы с маркерами циклов ИЛИ любыми переменными {{...}} + if '{{' not in full and 'loop:' not in full and 'loop_end' not in full: continue # Сохраняем форматирование первого run @@ -215,7 +215,11 @@ def expand_loops_in_zip(docx_path: str, loops: Dict[str, List[Dict]]) -> str: for idx, item in enumerate(items, 1): clone = template_clean for field, value in item.items(): - clone = clone.replace('{{item.%s}}' % field, str(value) if value else '—') + val_str = str(value) if value else '—' + # С префиксом item. + clone = clone.replace('{{item.%s}}' % field, val_str) + # Без префикса (алиасы {{name}}, {{pd_list}}, {{document}} и т.д.) + clone = clone.replace('{{%s}}' % field, val_str) clone = clone.replace('{{item.number}}', str(idx)) clone = clone.replace('{{number}}', str(idx)) expanded_parts.append(clone)