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)